Skip to content

Commit af7882e

Browse files
authored
Merge pull request #121 from OpenAF/codex/add-browser-context-for-svg-generation
refactor: split kvStore into separate memoryStore and todoList functions
2 parents 1329350 + 4e42feb commit af7882e

4 files changed

Lines changed: 183 additions & 25 deletions

File tree

mini-a-utils.js

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,25 +2605,21 @@ MiniUtilsTool.prototype.systemInfo = function(params) {
26052605

26062606
/**
26072607
* <odoc>
2608-
* <key>MiniUtilsTool.kvStore(params) : Object</key>
2608+
* <key>MiniUtilsTool.memoryStore(params) : Object</key>
26092609
* Simple key-value store for temporary data storage during execution.
26102610
* The `params` object can have the following properties:
26112611
* - `operation` (string, required): The operation to perform (set, get, delete, list, clear).
26122612
* - For set: `key` (string), `value` (any), `ttl` (optional milliseconds)
26132613
* - For get/delete: `key` (string)
26142614
* </odoc>
26152615
*/
2616-
MiniUtilsTool.prototype.kvStore = function(params) {
2616+
MiniUtilsTool.prototype.memoryStore = function(params) {
26172617
params = params || {}
26182618
var op = (params.operation || "").toLowerCase()
26192619

2620-
// Initialize store if not exists
26212620
if (isUnDef(this._kvStore)) {
26222621
this._kvStore = {}
26232622
}
2624-
if (isUnDef(this._todoList)) {
2625-
this._todoList = []
2626-
}
26272623

26282624
try {
26292625
if (op === "set") {
@@ -2688,7 +2684,33 @@ MiniUtilsTool.prototype.kvStore = function(params) {
26882684
var count = Object.keys(this._kvStore).length
26892685
this._kvStore = {}
26902686
return { cleared: count }
2691-
} else if (op === "todo-write") {
2687+
}
2688+
2689+
return "[ERROR] Unknown operation: " + op
2690+
} catch (e) {
2691+
return "[ERROR] " + __miniAErrMsg(e)
2692+
}
2693+
}
2694+
2695+
/**
2696+
* <odoc>
2697+
* <key>MiniUtilsTool.todoList(params) : Object</key>
2698+
* Lightweight in-memory todo list helper for temporary task tracking during execution.
2699+
* The `params` object can have the following properties:
2700+
* - `operation` (string, required): The operation to perform (write, read).
2701+
* - For write: `items` (array) or `item` (single value), `append` (boolean)
2702+
* </odoc>
2703+
*/
2704+
MiniUtilsTool.prototype.todoList = function(params) {
2705+
params = params || {}
2706+
var op = (params.operation || "").toLowerCase()
2707+
2708+
if (isUnDef(this._todoList)) {
2709+
this._todoList = []
2710+
}
2711+
2712+
try {
2713+
if (op === "write") {
26922714
var items = params.items
26932715
var item = params.item
26942716
var append = params.append === true
@@ -2704,10 +2726,10 @@ MiniUtilsTool.prototype.kvStore = function(params) {
27042726
} else if (isDef(item)) {
27052727
nextList.push(item)
27062728
}
2729+
27072730
this._todoList = nextList
27082731
return { count: this._todoList.length, items: this._todoList.slice(0) }
2709-
2710-
} else if (op === "todo-read") {
2732+
} else if (op === "read") {
27112733
return { count: this._todoList.length, items: this._todoList.slice(0) }
27122734
}
27132735

@@ -2753,8 +2775,8 @@ MiniUtilsTool._metadataByFn = (function() {
27532775
// System info operation types
27542776
var systemInfoOps = ["environment", "env", "platform", "cwd", "user", "memory", "disk"]
27552777

2756-
// KV store operation types
2757-
var kvStoreOps = ["set", "get", "delete", "list", "clear", "todo-write", "todo-read"]
2778+
var memoryStoreOps = ["set", "get", "delete", "list", "clear"]
2779+
var todoListOps = ["write", "read"]
27582780
var markdownOps = ["list", "search", "read", "get", "view", "cat"]
27592781
var skillOps = ["list", "search", "read", "get", "view", "cat", "render", "use", "expand", "apply", "invoke", "run"]
27602782

@@ -3037,22 +3059,37 @@ MiniUtilsTool._metadataByFn = (function() {
30373059
required : []
30383060
}
30393061
},
3040-
kvStore: {
3041-
name : "kvStore",
3042-
description: "Ephemeral state helper: key/value cache plus a lightweight todo list. Use for short-lived state between steps.",
3062+
memoryStore: {
3063+
name : "memoryStore",
3064+
description: "Ephemeral memory helper: store and retrieve short-lived key/value data between steps.",
30433065
inputSchema: {
30443066
type : "object",
30453067
properties: {
30463068
operation: {
30473069
type : "string",
3048-
description: "Operation type: set, get, delete, list, clear, todo-write, todo-read.",
3049-
enum : kvStoreOps
3070+
description: "Operation type: set, get, delete, list, clear.",
3071+
enum : memoryStoreOps
30503072
},
30513073
key : { type: "string", description: "Key for set/get/delete operations." },
30523074
value : { description: "Value to store (any type)." },
3053-
ttl : { type: "number", description: "Time-to-live in milliseconds." },
3054-
items : { type: "array", description: "Todo items array for todo-write operation." },
3055-
item : { type: "string", description: "Single todo item for todo-write operation." },
3075+
ttl : { type: "number", description: "Time-to-live in milliseconds." }
3076+
},
3077+
required : ["operation"]
3078+
}
3079+
},
3080+
todoList: {
3081+
name : "todoList",
3082+
description: "Lightweight in-memory todo list helper. Use for short task lists that only need write/read behavior.",
3083+
inputSchema: {
3084+
type : "object",
3085+
properties: {
3086+
operation: {
3087+
type : "string",
3088+
description: "Operation type: write or read.",
3089+
enum : todoListOps
3090+
},
3091+
items : { type: "array", description: "Todo items array for write operation." },
3092+
item : { description: "Single todo item for write operation." },
30563093
append : { type: "boolean", description: "Append to existing todo list when true." }
30573094
},
30583095
required : ["operation"]

mini-a.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7099,6 +7099,28 @@ MiniA.prototype._createUtilsMcpConfig = function(args) {
70997099
if (["delete", "remove", "rm", "deletefile"].indexOf(op) >= 0) return "Deleting path" + pathPart + "."
71007100
}
71017101

7102+
if (name === "memoryStore") {
7103+
if (op === "set") {
7104+
if (isString(payload.key) && payload.key.trim().length > 0) return "Storing memory key " + _quoted(payload.key.trim()) + "."
7105+
return "Storing memory value."
7106+
}
7107+
if (op === "get") {
7108+
if (isString(payload.key) && payload.key.trim().length > 0) return "Reading memory key " + _quoted(payload.key.trim()) + "."
7109+
return "Reading memory value."
7110+
}
7111+
if (op === "delete") {
7112+
if (isString(payload.key) && payload.key.trim().length > 0) return "Deleting memory key " + _quoted(payload.key.trim()) + "."
7113+
return "Deleting memory value."
7114+
}
7115+
if (op === "list") return "Listing memory keys."
7116+
if (op === "clear") return "Clearing memory store."
7117+
}
7118+
7119+
if (name === "todoList") {
7120+
if (op === "write") return "Updating todo list."
7121+
if (op === "read") return "Reading todo list."
7122+
}
7123+
71027124
if (name === "timeUtilities") {
71037125
if (op === "" || op === "current-time" || op === "current") {
71047126
if (isString(payload.timezone) && payload.timezone.trim().length > 0) {

tests/miniAUtils.js

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,85 @@
399399
ow.test.assert(malformedToon.format === "toon", true, "malformed validate-toon should report toon format")
400400
}
401401

402-
exports.testTodoOps = function() {
402+
exports.testMemoryStoreOps = function() {
403403
var tool = new MiniUtilsTool()
404404

405-
var writeResult = tool.kvStore({ operation: "todo-write", items: ["first", "second"] })
405+
var setResult = tool.memoryStore({ operation: "set", key: "alpha", value: 123 })
406+
ow.test.assert(setResult.stored === true, true, "Should store memory entry")
407+
408+
var getResult = tool.memoryStore({ operation: "get", key: "alpha" })
409+
ow.test.assert(getResult.found === true, true, "Should get stored memory entry")
410+
ow.test.assert(getResult.value === 123, true, "Should return stored memory value")
411+
412+
var listResult = tool.memoryStore({ operation: "list" })
413+
ow.test.assert(listResult.count === 1, true, "Should list stored memory keys")
414+
ow.test.assert(listResult.keys.indexOf("alpha") >= 0, true, "Should include stored key")
415+
416+
var deleteResult = tool.memoryStore({ operation: "delete", key: "alpha" })
417+
ow.test.assert(deleteResult.deleted === true, true, "Should delete stored memory entry")
418+
419+
var expiredSetResult = tool.memoryStore({ operation: "set", key: "ttl-key", value: "soon gone", ttl: 1 })
420+
ow.test.assert(expiredSetResult.stored === true, true, "Should store ttl entry")
421+
sleep(20, true)
422+
423+
var expiredGetResult = tool.memoryStore({ operation: "get", key: "ttl-key" })
424+
ow.test.assert(expiredGetResult.found === false, true, "Should expire ttl entry")
425+
ow.test.assert(expiredGetResult.expired === true, true, "Should flag expired ttl entry")
426+
427+
tool.memoryStore({ operation: "set", key: "beta", value: "x" })
428+
tool.memoryStore({ operation: "set", key: "gamma", value: "y" })
429+
var clearResult = tool.memoryStore({ operation: "clear" })
430+
ow.test.assert(clearResult.cleared === 2, true, "Should clear all remaining memory entries")
431+
}
432+
433+
exports.testTodoListOps = function() {
434+
var tool = new MiniUtilsTool()
435+
436+
var writeResult = tool.todoList({ operation: "write", items: ["first", "second"] })
406437
ow.test.assert(writeResult.count === 2, true, "Should write todo items")
407438

408-
var appendResult = tool.kvStore({ operation: "todo-write", item: "third", append: true })
439+
var appendResult = tool.todoList({ operation: "write", item: "third", append: true })
409440
ow.test.assert(appendResult.count === 3, true, "Should append todo items")
410441

411-
var readResult = tool.kvStore({ operation: "todo-read" })
442+
var overwriteResult = tool.todoList({ operation: "write", item: "reset" })
443+
ow.test.assert(overwriteResult.count === 1, true, "Should overwrite todo items when append is false")
444+
ow.test.assert(overwriteResult.items[0] === "reset", true, "Should replace todo list contents")
445+
446+
var readResult = tool.todoList({ operation: "read" })
447+
ow.test.assert(readResult.count === 1, true, "Should read todo items")
448+
ow.test.assert(readResult.items[0] === "reset", true, "Should read latest todo item")
449+
}
450+
451+
exports.testTodoListValidation = function() {
452+
var tool = new MiniUtilsTool()
453+
454+
var invalidItemsResult = tool.todoList({ operation: "write", items: "nope" })
455+
ow.test.assert(isString(invalidItemsResult) && invalidItemsResult.indexOf("[ERROR]") === 0, true, "Should reject non-array todo items")
456+
457+
var missingItemsResult = tool.todoList({ operation: "write" })
458+
ow.test.assert(isString(missingItemsResult) && missingItemsResult.indexOf("[ERROR]") === 0, true, "Should require todo items or item")
459+
}
460+
461+
exports.testMemoryStoreValidation = function() {
462+
var tool = new MiniUtilsTool()
463+
464+
var missingKeyResult = tool.memoryStore({ operation: "get" })
465+
ow.test.assert(isString(missingKeyResult) && missingKeyResult.indexOf("[ERROR]") === 0, true, "Should require key for memory get")
466+
467+
var missingValueResult = tool.memoryStore({ operation: "set", key: "alpha" })
468+
ow.test.assert(isString(missingValueResult) && missingValueResult.indexOf("[ERROR]") === 0, true, "Should require value for memory set")
469+
}
470+
471+
exports.testTodoOps = function() {
472+
var tool = new MiniUtilsTool()
473+
474+
var writeResult = tool.todoList({ operation: "write", items: ["first", "second"] })
475+
ow.test.assert(writeResult.count === 2, true, "Should write todo items through todoList")
476+
477+
var appendResult = tool.todoList({ operation: "write", item: "third", append: true })
478+
ow.test.assert(appendResult.count === 3, true, "Should append todo items through todoList")
479+
480+
var readResult = tool.todoList({ operation: "read" })
412481
ow.test.assert(readResult.count === 3, true, "Should read todo items")
413482
}
414483

@@ -563,6 +632,9 @@
563632
ow.test.assert(methods.indexOf("skills") >= 0, true, "Should include skills method")
564633
ow.test.assert(methods.indexOf("mathematics") >= 0, true, "Should include mathematics method")
565634
ow.test.assert(methods.indexOf("timeUtilities") >= 0, true, "Should include timeUtilities method")
635+
ow.test.assert(methods.indexOf("memoryStore") >= 0, true, "Should include memoryStore method")
636+
ow.test.assert(methods.indexOf("todoList") >= 0, true, "Should include todoList method")
637+
ow.test.assert(methods.indexOf("kvStore") === -1, true, "Should not include kvStore method")
566638

567639
var queryOps = metadata.filesystemQuery.inputSchema.properties.operation.enum || []
568640
ow.test.assert(queryOps.indexOf("glob") >= 0, true, "Should include glob operation in filesystemQuery")
@@ -573,8 +645,11 @@
573645
ow.test.assert(textOps.indexOf("json-to-toon") >= 0, true, "Should include json-to-toon operation in textUtilities")
574646
var validationOps = metadata.validationUtilities.inputSchema.properties.operation.enum || []
575647
ow.test.assert(validationOps.indexOf("validate-toon") >= 0, true, "Should include validate-toon operation in validationUtilities")
576-
var kvOps = metadata.kvStore.inputSchema.properties.operation.enum || []
577-
ow.test.assert(kvOps.indexOf("todo-write") >= 0, true, "Should include todo-write operation in kvStore")
648+
ow.test.assert(isUnDef(metadata.kvStore), true, "Should not include kvStore metadata")
649+
var memoryOps = metadata.memoryStore.inputSchema.properties.operation.enum || []
650+
ow.test.assert(memoryOps.indexOf("set") >= 0, true, "Should include set operation in memoryStore")
651+
var todoOps = metadata.todoList.inputSchema.properties.operation.enum || []
652+
ow.test.assert(todoOps.indexOf("write") >= 0, true, "Should include write operation in todoList")
578653
var markdownOps = metadata.markdownFiles.inputSchema.properties.operation.enum || []
579654
ow.test.assert(markdownOps.indexOf("search") >= 0, true, "Should include search operation in markdownFiles")
580655
var skillOps = metadata.skills.inputSchema.properties.operation.enum || []

tests/miniAUtils.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ jobs:
7272
to : oJob Test
7373
exec: args.func = args.tests.testTextAndValidationToon
7474

75+
- name: MiniA Utils Tests::MemoryStoreOps
76+
from: MiniA Utils Tests::Init
77+
to : oJob Test
78+
exec: args.func = args.tests.testMemoryStoreOps
79+
80+
- name: MiniA Utils Tests::TodoListOps
81+
from: MiniA Utils Tests::Init
82+
to : oJob Test
83+
exec: args.func = args.tests.testTodoListOps
84+
85+
- name: MiniA Utils Tests::TodoListValidation
86+
from: MiniA Utils Tests::Init
87+
to : oJob Test
88+
exec: args.func = args.tests.testTodoListValidation
89+
90+
- name: MiniA Utils Tests::MemoryStoreValidation
91+
from: MiniA Utils Tests::Init
92+
to : oJob Test
93+
exec: args.func = args.tests.testMemoryStoreValidation
94+
7595
- name: MiniA Utils Tests::TodoOps
7696
from: MiniA Utils Tests::Init
7797
to : oJob Test
@@ -169,6 +189,10 @@ todo:
169189
- MiniA Utils Tests::EditFile
170190
- MiniA Utils Tests::WebFetch
171191
- MiniA Utils Tests::TextAndValidationToon
192+
- MiniA Utils Tests::MemoryStoreOps
193+
- MiniA Utils Tests::TodoListOps
194+
- MiniA Utils Tests::TodoListValidation
195+
- MiniA Utils Tests::MemoryStoreValidation
172196
- MiniA Utils Tests::TodoOps
173197
- MiniA Utils Tests::PathSecurity
174198
- MiniA Utils Tests::MarkdownFiles

0 commit comments

Comments
 (0)