JSON operations via aOperations (sTool = "fs")

When the prompt starts with {, the Agent decodes the JSON and looks for aOperations. Each operation has this basic structure:

{ "aOperations": [ { "sBase": "app|web|core", "sPath": "data/test.txt", "sMode": "overwrite|append|replace|read", "sContent": "...", // for overwrite/append "sSearch": "...", // for replace "sReplace": "..." // for replace } ]
} 

Supported filesystem modes:

  • overwrite – ignore old content and write sContent.
  • append – keep old content and append sContent.
  • replacestr_replace(sSearch, sReplace, oldContent) and write back.
  • read – read-only; returns sContent in the result without calling WriteFile().

10.1 Overwrite data/test.txt (app base)

{ "aOperations": [ { "sBase": "app", "sPath": "data/test.txt", "sMode": "overwrite", "sContent": "Hello from TypeStack Magic after update" } ]
} 

The result includes iNewLength for the new file length.

10.2 Append to an Agent log

{ "aOperations": [ { "sBase": "app", "sPath": "data/agent/agent-selftest.log", "sMode": "append", "sContent": "[SELFTEST] App layer OK at 2025-12-04 23:59:59\\n" } ]
} 

If the file does not exist, it is treated as empty and created.

10.3 Write under the web base

{ "aOperations": [ { "sBase": "web", "sPath": "data/agent/agent-web-selftest.txt", "sMode": "overwrite", "sContent": "Hello from TypeStack Magic on web base" } ]
} 

The Agent resolves the web base via DOCUMENT_ROOT or public_html/private_html under the application root and writes there.

10.4 Multi-step workflow in one prompt

{ "aOperations": [ { "sBase": "app", "sPath": "data/agent/agent-selftest.log", "sMode": "append", "sContent": "[SELFTEST] Combined operation started\\n" }, { "sBase": "app", "sPath": "data/agent/fs-selftest-app.txt", "sMode": "overwrite", "sContent": "App base OK" }, { "sBase": "web", "sPath": "data/agent/fs-selftest-web.txt", "sMode": "overwrite", "sContent": "Web base OK" }, { "sBase": "app", "sPath": "data/agent/agent-selftest.log", "sMode": "append", "sContent": "[SELFTEST] Combined operation finished\\n" } ]
} 

The response contains four entries in aOpResults, one for each operation, each with its own bSuccess flag and debug output.

10.5 Search and replace in data/test.txt

{ "aOperations": [ { "sBase": "app", "sPath": "data/test.txt", "sMode": "replace", "sSearch": "Hoi Open AI :)", "sReplace": "Hello from TypeStack Magic after replace" } ]
} 

Internally this becomes:

str_replace("Hoi Open AI :)", "Hello from TypeStack Magic after replace", $sOldContent); 

The modified content is written back via WriteFile(), and the new length is reported in iNewLength.

10.6 Read-only operation (sMode = "read")

{ "aOperations": [ { "sBase": "app", "sPath": "data/test.txt", "sMode": "read" } ]
} 

The result includes:

  • sMode, sBase, sPath, resolved sFullPath.
  • sContent with the current file content.
  • aDebug with read details and content length.

Read mode respects the same base rules as other operations (app, web, core).