swift-agent-debug-log
Skill9 starsChanged 6 months agoMITView on GitHub
Instrument Swift/iOS apps for Cursor DEBUG MODE: NDJSON hypothesis logs on the host or simulator Documents. Use with XcodeBazelMCP agent_debug tools (clear, read, pull, repro) instead of Read/delete_file on host paths from sim code.
In this repository7 other files it gives its agents.
- cli-developmentSkill
- device-and-uiSkill
- example-projectSkill
- mcp-setupSkill
- simulator-workflowSkill
- tool-handler-developmentSkill
- swift-agent-debug-logSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 33
If no host path is writable, append NDJSON to:
- Very specific: line 89
If empty on host → bazel_ios_agent_debug_log_pull with bundleId + optional destPath
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Swift Agent Debug Log (Cursor DEBUG MODE)
XcodeBazelMCP owns runtime (build, launch, read logs). This skill is the protocol (NDJSON schema, hypothesisId, session cleanup).
Log path strategy
| Runtime | Where Swift writes | How the agent reads |
| macOS / unit tests | Host path from env | bazel_ios_agent_debug_log_read |
| iOS Simulator | Documents/agent-debug.ndjson (sandbox-safe) | bazel_ios_agent_debug_log_pull or env if using host mount |
Never hardcode repo paths like Apps/Consumer/.cursor/debug-*.log in app code — the sim sandbox cannot write there.
Environment (preferred for host / tests)
bazel_ios_build_and_run / bazel_ios_agent_debug_repro pass via launchEnv → SIMCTL_CHILD_*:
AGENT_DEBUG_LOG_PATH— absolute host path (e.g.<workspace>/.cursor/debug-{session}.log)AGENT_DEBUG_SESSION_ID— Cursor debug session id
Swift reads ProcessInfo.processInfo.environment and appends one NDJSON object per line.
Simulator fallback
If no host path is writable, append NDJSON to:
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]/agent-debug.ndjson
Then pull with bazel_ios_agent_debug_log_pull (destPath optional copy to .cursor/debug-*.log).
Swift instrumentation (minimal)
func agentDebugLog(
location: String,
message: String,
data: [String: Any] = [:],
hypothesisId: String,
runId: String = "pre-fix"
) {
let env = ProcessInfo.processInfo.environment
let sessionId = env["AGENT_DEBUG_SESSION_ID"] ?? ""
let payload: [String: Any] = [
"sessionId": sessionId,
"location": location,
"message": message,
"data": data,
"hypothesisId": hypothesisId,
"runId": runId,
"timestamp": Int(Date().timeIntervalSince1970 * 1000),
]
guard let line = try? JSONSerialization.data(withJSONObject: payload),
let str = String(data: line, encoding: .utf8) else { return }
let row = str + "\n"
if let path = env["AGENT_DEBUG_LOG_PATH"], !path.isEmpty {
if let handle = FileHandle(forWritingAtPath: path) {
handle.seekToEndOfFile(); handle.write(Data(row.utf8)); try? handle.close()
} else {
FileManager.default.createFile(atPath: path, contents: Data(row.utf8))
}
return
}
let doc = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let url = doc.appendingPathComponent("agent-debug.ndjson")
if let handle = try? FileHandle(forWritingTo: url) {
handle.seekToEndOfFile(); handle.write(Data(row.utf8)); try? handle.close()
} else {
try? row.write(to: url, atomically: true, encoding: .utf8)
}
}Wrap calls in // #region agent log … // #endregion so Xcode folds them.
Agent workflow (use MCP tools, not raw file tools)
bazel_ios_agent_debug_log_clear—{ "logPath": "<abs>/.cursor/debug-{session}.log" }bazel_ios_agent_debug_reproorbazel_ios_build_and_runwithlaunchEnv/ repro setsAGENT_DEBUG_*- User reproduces the bug
bazel_ios_agent_debug_log_read— filterhypothesisId,runId; usehypothesisStatusHintsfor CONFIRMED/REJECTED hints- If empty on host →
bazel_ios_agent_debug_log_pullwithbundleId+ optionaldestPath
MCP resource: xcodebazel://agent-debug-log?path=<url-encoded-abs-path>
NDJSON line schema
{
"sessionId": "522bed",
"location": "MyType.swift:42",
"message": "branch taken",
"data": { "count": 3 },
"hypothesisId": "A",
"runId": "pre-fix",
"timestamp": 1733456789000
}Optional: os_log transport
bazel_ios_log_capture_start with jsonLinesOnly: true or messageContains: "agentDebugLog" — noisier than file pull; use when you cannot add file IO.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

