@iinm/plain-agent 1.8.0 → 1.8.2

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": "@iinm/plain-agent",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "A lightweight CLI-based coding agent",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,9 +9,9 @@
9
9
  "url": "git+https://github.com/iinm/plain-agent.git"
10
10
  },
11
11
  "bin": {
12
- "plain": "./bin/plain",
13
- "plain-notify-desktop": "./bin/plain-notify-desktop",
14
- "plain-sandbox": "./sandbox/bin/plain-sandbox"
12
+ "plain": "bin/plain",
13
+ "plain-notify-desktop": "bin/plain-notify-desktop",
14
+ "plain-sandbox": "sandbox/bin/plain-sandbox"
15
15
  },
16
16
  "files": [
17
17
  "bin",
@@ -20,8 +20,9 @@
20
20
  "src/**/*.mjs",
21
21
  "src/**/*.d.ts",
22
22
  "!src/**/*.test.mjs",
23
+ "!src/**/*.test.*.mjs",
23
24
  "!src/**/*.playground.mjs",
24
- "!src/utils/test/"
25
+ "!src/**/test/"
25
26
  ],
26
27
  "engines": {
27
28
  "node": ">=22"
@@ -34,11 +35,10 @@
34
35
  },
35
36
  "dependencies": {
36
37
  "diff": "^8.0.4",
37
- "js-yaml": "^4.1.1"
38
+ "yaml": "^2.8.3"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@biomejs/biome": "^2.4.12",
41
- "@types/js-yaml": "^4.0.9",
42
42
  "@types/node": "^22.19.17",
43
43
  "typescript": "^6.0.2"
44
44
  }
@@ -3,7 +3,7 @@
3
3
  import crypto from "node:crypto";
4
4
  import fs from "node:fs/promises";
5
5
  import path from "node:path";
6
- import yaml from "js-yaml";
6
+ import { parse as parseYaml } from "yaml";
7
7
  import {
8
8
  AGENT_CACHE_DIR,
9
9
  AGENT_PROJECT_METADATA_DIR,
@@ -246,7 +246,7 @@ function parseAgentRole(relativePath, fileContent, fullPath, idPrefix = "") {
246
246
  let frontmatter;
247
247
  try {
248
248
  frontmatter = /** @type {{description?:string; import?:string}} */ (
249
- yaml.load(match[1])
249
+ parseYaml(match[1])
250
250
  );
251
251
  } catch (_err) {
252
252
  return {
@@ -4,7 +4,7 @@ import { execFileSync } from "node:child_process";
4
4
  import crypto from "node:crypto";
5
5
  import fs from "node:fs/promises";
6
6
  import path from "node:path";
7
- import yaml from "js-yaml";
7
+ import { parse as parseYaml } from "yaml";
8
8
  import {
9
9
  AGENT_CACHE_DIR,
10
10
  AGENT_PROJECT_METADATA_DIR,
@@ -279,7 +279,7 @@ function parsePrompt(relativePath, fileContent, fullPath, idPrefix = "") {
279
279
  try {
280
280
  frontmatter =
281
281
  /** @type {{description?:string; import?:string; "user-invocable"?:boolean}} */ (
282
- yaml.load(match[1])
282
+ parseYaml(match[1])
283
283
  );
284
284
  } catch (_err) {
285
285
  return {
@@ -5,12 +5,26 @@ import { createHash, createHmac } from "node:crypto";
5
5
  * @typedef {{ accessKeyId: string, secretAccessKey: string, sessionToken?: string }} AwsCredentials
6
6
  */
7
7
 
8
+ /** @type {Map<string, { credentials: AwsCredentials, expiration: Date }>} */
9
+ const credentialCache = new Map();
10
+
11
+ const EXPIRATION_MARGIN_MS = 60 * 1000;
12
+
8
13
  /**
9
14
  * Load AWS credentials for the given profile using the AWS CLI.
15
+ * Results are cached and reused until the credentials expire.
10
16
  * @param {string} profile
11
17
  * @returns {Promise<AwsCredentials>}
12
18
  */
13
19
  export async function loadAwsCredentials(profile) {
20
+ const cached = credentialCache.get(profile);
21
+ if (
22
+ cached &&
23
+ Date.now() < cached.expiration.getTime() - EXPIRATION_MARGIN_MS
24
+ ) {
25
+ return cached.credentials;
26
+ }
27
+
14
28
  /** @type {string} */
15
29
  const stdout = await new Promise((resolve, reject) => {
16
30
  execFile(
@@ -37,11 +51,20 @@ export async function loadAwsCredentials(profile) {
37
51
  );
38
52
  }
39
53
  }
40
- return {
54
+ const credentials = {
41
55
  accessKeyId: parsed.AccessKeyId,
42
56
  secretAccessKey: parsed.SecretAccessKey,
43
57
  ...(parsed.SessionToken && { sessionToken: parsed.SessionToken }),
44
58
  };
59
+
60
+ if (parsed.Expiration) {
61
+ const expiration = new Date(parsed.Expiration);
62
+ if (!Number.isNaN(expiration.getTime())) {
63
+ credentialCache.set(profile, { credentials, expiration });
64
+ }
65
+ }
66
+
67
+ return credentials;
45
68
  }
46
69
 
47
70
  /**
@@ -5,7 +5,7 @@ import { execFile } from "node:child_process";
5
5
  * @returns {Promise<string>}
6
6
  */
7
7
  export async function getGoogleCloudAccessToken(account) {
8
- const accountOption = account?.endsWith("iam.gserviceaccount.com")
8
+ const accountOption = account?.endsWith(".iam.gserviceaccount.com")
9
9
  ? ["--impersonate-service-account", account]
10
10
  : account
11
11
  ? [account]
@@ -1,83 +0,0 @@
1
- /**
2
- * Mock MCP server for testing.
3
- * Speaks JSON-RPC 2.0 over stdio.
4
- * Handles: initialize, notifications/initialized, tools/list, tools/call.
5
- */
6
-
7
- import { createInterface } from "node:readline";
8
-
9
- const rl = createInterface({ input: process.stdin });
10
-
11
- rl.on("line", (line) => {
12
- let msg;
13
- try {
14
- msg = JSON.parse(line);
15
- } catch {
16
- return;
17
- }
18
-
19
- if (msg.method === "initialize") {
20
- respond(msg.id, {
21
- protocolVersion: "2025-03-26",
22
- capabilities: {},
23
- serverInfo: { name: "mock", version: "0.0.0" },
24
- });
25
- return;
26
- }
27
-
28
- if (msg.method === "notifications/initialized") {
29
- return;
30
- }
31
-
32
- if (msg.method === "tools/list") {
33
- respond(msg.id, {
34
- tools: [
35
- {
36
- name: "echo",
37
- description: "Echo tool",
38
- inputSchema: {
39
- type: "object",
40
- properties: { text: { type: "string" } },
41
- },
42
- },
43
- {
44
- name: "add",
45
- description: "Add numbers",
46
- inputSchema: {
47
- type: "object",
48
- properties: {
49
- a: { type: "number" },
50
- b: { type: "number" },
51
- },
52
- },
53
- },
54
- ],
55
- });
56
- return;
57
- }
58
-
59
- if (msg.method === "tools/call") {
60
- const { name, arguments: args } = msg.params;
61
- if (name === "echo") {
62
- respond(msg.id, { content: [{ type: "text", text: args.text }] });
63
- } else if (name === "add") {
64
- respond(msg.id, {
65
- content: [{ type: "text", text: String(args.a + args.b) }],
66
- });
67
- } else if (name === "error_tool") {
68
- respondError(msg.id, -1, "tool failed");
69
- }
70
- }
71
- });
72
-
73
- /** @param {number} id @param {unknown} result */
74
- function respond(id, result) {
75
- process.stdout.write(`${JSON.stringify({ jsonrpc: "2.0", id, result })}\n`);
76
- }
77
-
78
- /** @param {number} id @param {number} code @param {string} message */
79
- function respondError(id, code, message) {
80
- process.stdout.write(
81
- `${JSON.stringify({ jsonrpc: "2.0", id, error: { code, message } })}\n`,
82
- );
83
- }