@kobinflow/canvas-agent 0.6.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 (50) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +159 -0
  3. package/agent-instructions.md +13 -0
  4. package/dist/agent/claude.d.ts +3 -0
  5. package/dist/agent/claude.js +54 -0
  6. package/dist/agent/codex-client.d.ts +139 -0
  7. package/dist/agent/codex-client.js +937 -0
  8. package/dist/agent/codex-event-history.d.ts +21 -0
  9. package/dist/agent/codex-event-history.js +163 -0
  10. package/dist/agent/codex-history.d.ts +46 -0
  11. package/dist/agent/codex-history.js +822 -0
  12. package/dist/agent/codex-protocol.d.ts +335 -0
  13. package/dist/agent/codex-protocol.js +1 -0
  14. package/dist/agent/codex.d.ts +178 -0
  15. package/dist/agent/codex.js +509 -0
  16. package/dist/agent/message-metadata.d.ts +51 -0
  17. package/dist/agent/message-metadata.js +378 -0
  18. package/dist/agent/types.d.ts +45 -0
  19. package/dist/agent/types.js +1 -0
  20. package/dist/canvas/operations.d.ts +13 -0
  21. package/dist/canvas/operations.js +167 -0
  22. package/dist/canvas/schemas.d.ts +989 -0
  23. package/dist/canvas/schemas.js +155 -0
  24. package/dist/canvas/session.d.ts +163 -0
  25. package/dist/canvas/session.js +523 -0
  26. package/dist/canvas/tools.d.ts +214 -0
  27. package/dist/canvas/tools.js +27 -0
  28. package/dist/canvas/types.d.ts +34 -0
  29. package/dist/canvas/types.js +1 -0
  30. package/dist/config.d.ts +30 -0
  31. package/dist/config.js +86 -0
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.js +7 -0
  34. package/dist/server/http.d.ts +2 -0
  35. package/dist/server/http.js +576 -0
  36. package/dist/server/mcp.d.ts +2 -0
  37. package/dist/server/mcp.js +27 -0
  38. package/dist/skills/store.d.ts +54 -0
  39. package/dist/skills/store.js +426 -0
  40. package/dist/utils/agent-runtime.d.ts +8 -0
  41. package/dist/utils/agent-runtime.js +33 -0
  42. package/dist/utils/date.d.ts +2 -0
  43. package/dist/utils/date.js +7 -0
  44. package/dist/utils/logger.d.ts +17 -0
  45. package/dist/utils/logger.js +81 -0
  46. package/dist/utils/value.d.ts +5 -0
  47. package/dist/utils/value.js +8 -0
  48. package/dist/version-check.d.ts +2 -0
  49. package/dist/version-check.js +65 -0
  50. package/package.json +55 -0
@@ -0,0 +1,65 @@
1
+ import { execFile, execFileSync } from "node:child_process";
2
+ import { createRequire } from "node:module";
3
+ import { promisify } from "node:util";
4
+ import { VERSION } from "./config.js";
5
+ import { logger } from "./utils/logger.js";
6
+ const require = createRequire(import.meta.url);
7
+ const execFileAsync = promisify(execFile);
8
+ const CODEX_VERSION = String(require("@openai/codex/package.json").version);
9
+ /** 输出当前版本,并在后台检查 npm 最新版本。 */
10
+ export function checkVersions() {
11
+ const localCodexVersion = commandVersion("codex");
12
+ logger.info("Canvas Agent version", { version: VERSION });
13
+ logger.info("Bundled Codex version", { version: CODEX_VERSION });
14
+ logger.info("Local Codex version", { version: localCodexVersion || "not found" });
15
+ if (!localCodexVersion) {
16
+ logger.warn("Local Codex was not found. Install the latest version with: npm install -g @openai/codex@latest");
17
+ }
18
+ else if (localCodexVersion !== CODEX_VERSION) {
19
+ logger.warn(`Bundled Codex ${CODEX_VERSION} does not match local Codex ${localCodexVersion}. Keep both current with: npm install -g @openai/codex@latest && npx -y @kobinflow/canvas-agent@latest`);
20
+ }
21
+ void checkLatestVersions(localCodexVersion);
22
+ }
23
+ /** 查询 npm,提醒升级不再维护的旧版本。 */
24
+ async function checkLatestVersions(localCodexVersion) {
25
+ try {
26
+ const [latestAgent, latestCodex] = await Promise.all([
27
+ npmVersion("@kobinflow/canvas-agent"),
28
+ npmVersion("@openai/codex"),
29
+ ]);
30
+ if (isOlder(VERSION, latestAgent))
31
+ logger.warn(`Update available: Canvas Agent ${VERSION} -> ${latestAgent}. Run: npx -y @kobinflow/canvas-agent@latest`);
32
+ if (isOlder(CODEX_VERSION, latestCodex))
33
+ logger.warn(`Update available: bundled Codex ${CODEX_VERSION} -> ${latestCodex}. Upgrade Canvas Agent with: npx -y @kobinflow/canvas-agent@latest`);
34
+ if (localCodexVersion && isOlder(localCodexVersion, latestCodex))
35
+ logger.warn(`Update available: local Codex ${localCodexVersion} -> ${latestCodex}. Run: npm install -g @openai/codex@latest`);
36
+ }
37
+ catch {
38
+ logger.warn("Unable to check the latest npm versions; startup will continue.");
39
+ }
40
+ }
41
+ /** 读取本机命令输出中的语义版本号。 */
42
+ function commandVersion(command) {
43
+ try {
44
+ return execFileSync(command, ["--version"], { encoding: "utf8", timeout: 5_000 }).match(/\d+\.\d+\.\d+/)?.[0] || "";
45
+ }
46
+ catch {
47
+ return "";
48
+ }
49
+ }
50
+ /** 读取 npm 包的最新版本。 */
51
+ async function npmVersion(name) {
52
+ const command = process.platform === "win32" ? "npm.cmd" : "npm";
53
+ const { stdout } = await execFileAsync(command, ["view", name, "version"], { encoding: "utf8", timeout: 10_000 });
54
+ return stdout.trim();
55
+ }
56
+ /** 比较仅包含数字段的稳定版语义版本。 */
57
+ function isOlder(current, latest) {
58
+ const left = current.split(".").map(Number);
59
+ const right = latest.split(".").map(Number);
60
+ for (let index = 0; index < Math.max(left.length, right.length); index++) {
61
+ if ((left[index] || 0) !== (right[index] || 0))
62
+ return (left[index] || 0) < (right[index] || 0);
63
+ }
64
+ return false;
65
+ }
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@kobinflow/canvas-agent",
3
+ "version": "0.6.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "canvas-agent": "dist/index.js",
10
+ "dianran-agent": "dist/index.js"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "agent-instructions.md",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "scripts": {
19
+ "dev": "tsx src/index.ts",
20
+ "debug": "tsx src/index.ts --debug",
21
+ "test": "tsx --test src/config.test.ts src/canvas/operations.test.ts src/canvas/session.test.ts src/agent/codex-client.test.ts src/agent/codex-history.test.ts src/agent/message-metadata.test.ts src/skills/store.test.ts src/utils/agent-runtime.test.ts",
22
+ "build": "tsc -p tsconfig.json",
23
+ "start": "node dist/index.js",
24
+ "prepack": "npm run build"
25
+ },
26
+ "dependencies": {
27
+ "@modelcontextprotocol/sdk": "^1.12.1",
28
+ "@openai/codex": "0.146.0",
29
+ "express": "^5.1.0",
30
+ "gray-matter": "^4.0.3",
31
+ "strip-ansi": "7.2.0",
32
+ "winston": "^3.19.0",
33
+ "yaml": "^2.9.0",
34
+ "zod": "^3.25.0"
35
+ },
36
+ "devDependencies": {
37
+ "@types/express": "^5.0.0",
38
+ "@types/node": "^22.0.0",
39
+ "tsx": "^4.19.0",
40
+ "typescript": "^5.8.0"
41
+ },
42
+ "engines": {
43
+ "node": ">=18"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "description": "Local agent bridge that lets Codex / Claude Code operate the Dianran (点染) canvas over MCP.",
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/kobingogo/dianran.git",
52
+ "directory": "canvas-agent"
53
+ },
54
+ "homepage": "https://github.com/kobingogo/dianran/tree/main/canvas-agent"
55
+ }