agentleFS
DebugSwiftDebugSwift/XcodeBazelMCP/.agents/skills/swift-agent-debug-log/SKILL.md

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.

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
  1. Distinctive:

    If no host path is writable, append NDJSON to:

    line 33
  2. Very specific:

    If empty on host → bazel_ios_agent_debug_log_pull with bundleId + optional destPath

    line 89

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

RuntimeWhere Swift writesHow the agent reads
macOS / unit testsHost path from envbazel_ios_agent_debug_log_read
iOS SimulatorDocuments/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)

  1. bazel_ios_agent_debug_log_clear — { "logPath": "<abs>/.cursor/debug-{session}.log" }
  2. bazel_ios_agent_debug_repro or bazel_ios_build_and_run with launchEnv / repro sets AGENT_DEBUG_*
  3. User reproduces the bug
  4. bazel_ios_agent_debug_log_read — filter hypothesisId, runId; use hypothesisStatusHints for CONFIRMED/REJECTED hints
  5. If empty on host → bazel_ios_agent_debug_log_pull with bundleId + optional destPath

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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.