[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M72ZXP10MZQ6NF1MPJBF0F9K":3,"skill-same:01M72ZXP10MZQ6NF1MPJBF0F9K":47},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":28,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M72ZXP10MZQ6NF1MPJBF0F9K","agent-middleware-gate",null,"Horonomos-laps\u002FYana-AI","Horonomos-laps","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F355299122?v=4","01M76B3QPXE88ET2SQPDPVATZT"," Horonomos-laps","01M72ZQRJPCYPSSWT4D00VJR2A",13,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FHoronomos-laps\u002FYana-AI\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fagent-middleware-gate\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: agent-middleware-gate\ndescription: Intercept-layer skill for wrapping all agent tool calls through a sanitize-mutate-execute proxy pipeline. Onion middleware composition (koa), request\u002Fresponse interceptors (axios), scope-aware handler chains (express), near-zero-latency proxy routing (caddy), and in-memory pipe streams (piping-server). Implements core\u002Fscripts\u002Ftool-proxy.sh. Sources: koajs\u002Fkoa, axios\u002Faxios, expressjs\u002Fexpress, caddyserver\u002Fcaddy, nwtgck\u002Fpiping-server.\norigin: yana-ai — synthesized from koajs\u002Fkoa, axios\u002Faxios, expressjs\u002Fexpress, caddyserver\u002Fcaddy, nwtgck\u002Fpiping-server\nlicense: Apache-2.0\nversion: 1.0.0\ncompatibility: yana-ai >= 1.3.45\n---\n\n# \u002Fintercept-layer\n\n## When to Use\n\n- Every agent tool call must pass through intercept → sanitize → mutate → execute\n- \"The agent ran a command with unsafe params — how do we catch it before exec?\"\n- Need to auto-harden a command (add timeout, resource cap) instead of just blocking it\n- Pipeline needs layers that act both before AND after execution (onion model)\n\n## Do NOT use for\n\n- In-process function calls with no shell\u002Fexec boundary\n- Read-only introspection (no mutation needed)\n\n---\n\n## Architecture: Four-Phase Proxy Pipeline\n\n```\nAgent emits tool call\n       │\n       ▼\n┌──────────────────────────────────────────┐\n│  PHASE 1 — INTERCEPT                     │\n│  Read raw command + args, log to audit   │\n│  Source: koa onion — outer layer entry   │\n└──────────────────┬───────────────────────┘\n                   │\n                   ▼\n┌──────────────────────────────────────────┐\n│  PHASE 2 — SANITIZE  (Gate L2)           │\n│  Strip injection chars (; | & ` $())     │\n│  Auto-quote bare variables               │\n│  Block subshell escape ($() \u003C() `)       │\n│  Source: axios request interceptor       │\n└──────────────────┬───────────────────────┘\n                   │ clean args\n                   ▼\n┌──────────────────────────────────────────┐\n│  PHASE 3 — MUTATE  (Gate L1)             │\n│  Auto-add missing safety config:         │\n│    • timeout wrapper                     │\n│    • ulimit memory cap                   │\n│    • network flag if missing             │\n│  Source: caddy handler chain mutation    │\n└──────────────────┬───────────────────────┘\n                   │ hardened command\n                   ▼\n           [tool executes]\n                   │\n                   ▼\n┌──────────────────────────────────────────┐\n│  PHASE 4 — RESPONSE INTERCEPT  (Gate L0) │\n│  Sanitize output (strip PII \u002F secrets)   │\n│  Cap result size (16KB)                  │\n│  Audit log result hash                   │\n│  Source: axios response interceptor      │\n└──────────────────────────────────────────┘\n```\n\n---\n\n## Phase 1 — Onion Composition (koa pattern)\n\n```typescript\n\u002F\u002F Koa's compose() — each middleware wraps the next layer\n\u002F\u002F Before-call logic runs top-down; after-call logic runs bottom-up\ntype Next = () => Promise\u003Cvoid>\ntype Middleware = (ctx: ToolContext, next: Next) => Promise\u003Cvoid>\n\nfunction compose(middlewares: Middleware[]) {\n  return function (ctx: ToolContext): Promise\u003Cvoid> {\n    let index = -1\n\n    function dispatch(i: number): Promise\u003Cvoid> {\n      if (i \u003C= index) return Promise.reject(new Error('next() called multiple times'))\n      index = i\n      const fn = middlewares[i]\n      if (!fn) return Promise.resolve()  \u002F\u002F end of chain → execute tool\n      return Promise.resolve(fn(ctx, () => dispatch(i + 1)))\n    }\n\n    return dispatch(0)\n  }\n}\n\n\u002F\u002F Usage: wrap any layer — PRE logic runs before next(), POST logic after\nconst interceptLayer: Middleware = async (ctx, next) => {\n  ctx.interceptedAt = Date.now()\n  auditLog.record({ phase: 'intercept', tool: ctx.tool, args: ctx.args })\n\n  await next()  \u002F\u002F ← inner layers run here\n\n  \u002F\u002F POST: runs after tool execution and all inner layers complete\n  auditLog.record({ phase: 'result', tool: ctx.tool, elapsed: Date.now() - ctx.interceptedAt })\n}\n\n\u002F\u002F Rule: compose() order = outermost first, innermost = actual execute\n\u002F\u002F Rule: never call next() twice in the same middleware — throws\n```\n\n---\n\n## Phase 2 — Sanitize (axios interceptor pattern)\n\n```typescript\n\u002F\u002F Axios-style: register named interceptors that can mutate or reject\nclass InterceptorManager\u003CT> {\n  #handlers: Array\u003C{ name: string; fn: (v: T) => T | Promise\u003CT> }> = []\n\n  use(name: string, fn: (v: T) => T | Promise\u003CT>) {\n    this.#handlers.push({ name, fn })\n    return this  \u002F\u002F chainable\n  }\n\n  async run(value: T): Promise\u003CT> {\n    let current = value\n    for (const { name, fn } of this.#handlers) {\n      current = await fn(current)\n    }\n    return current\n  }\n}\n\n\u002F\u002F Request (pre-exec) interceptors\nconst requestInterceptors = new InterceptorManager\u003CToolContext>()\n\nrequestInterceptors\n  .use('strip-injection-chars', (ctx) => {\n    const INJECTION_CHARS = \u002F[;&|`$>\u003C\\n]\u002Fg\n    ctx.args = Object.fromEntries(\n      Object.entries(ctx.args).map(([k, v]) => [\n        k,\n        typeof v === 'string' ? v.replace(INJECTION_CHARS, '') : v,\n      ])\n    )\n    return ctx\n  })\n  .use('block-subshell', (ctx) => {\n    const SUBSHELL = \u002F\\$\\(|\\`|\u003C\\(\u002F\n    const raw = JSON.stringify(ctx.args)\n    if (SUBSHELL.test(raw)) {\n      throw Object.assign(new Error('subshell escape attempt in args'), { gate: 'L2', exitCode: 3 })\n    }\n    return ctx\n  })\n  .use('auto-quote-vars', (ctx) => {\n    \u002F\u002F Bare $VAR in string args → \"${VAR}\" to prevent word splitting\n    ctx.args = Object.fromEntries(\n      Object.entries(ctx.args).map(([k, v]) => [\n        k,\n        typeof v === 'string' ? v.replace(\u002F\\$([A-Za-z_][A-Za-z0-9_]*)\u002Fg, '\"$${$1}\"') : v,\n      ])\n    )\n    return ctx\n  })\n\n\u002F\u002F Response interceptors — post-exec output sanitize\nconst responseInterceptors = new InterceptorManager\u003CToolContext>()\n\nresponseInterceptors\n  .use('strip-pii', (ctx) => {\n    if (ctx.result) ctx.result = piiScrub(ctx.result)\n    return ctx\n  })\n  .use('size-cap', (ctx) => {\n    const MAX = 16 * 1024\n    if (ctx.result && ctx.result.length > MAX) {\n      ctx.result = ctx.result.slice(0, MAX) + '\\n[TRUNCATED]'\n    }\n    return ctx\n  })\n\n\u002F\u002F Rule: interceptors run in registration order — security checks must be first\n\u002F\u002F Rule: throw to abort pipeline; return mutated ctx to continue\n```\n\n---\n\n## Phase 3 — Mutate (caddy handler chain pattern)\n\n```typescript\n\u002F\u002F Caddy insight: match → handler chain → upstream\n\u002F\u002F Mutation adds missing safety config BEFORE exec, not just block\u002Freject\n\ninterface MutationRule {\n  match:  (ctx: ToolContext) => boolean\n  mutate: (ctx: ToolContext) => ToolContext\n}\n\nconst MUTATION_RULES: MutationRule[] = [\n  {\n    \u002F\u002F Auto-add timeout if not present\n    match:  (ctx) => ctx.tool === 'Bash' && !ctx.args.timeout,\n    mutate: (ctx) => {\n      ctx.args = { ...ctx.args, timeout: Number(process.env.YAMTAM_TOOL_TIMEOUT ?? 30000) }\n      return ctx\n    },\n  },\n  {\n    \u002F\u002F Auto-add --no-network for file-only operations\n    match:  (ctx) => ctx.tool === 'Read' && !(ctx.args as any).url,\n    mutate: (ctx) => {\n      ;(ctx.args as any).__networkBlocked = true\n      return ctx\n    },\n  },\n  {\n    \u002F\u002F Auto-wrap destructive Bash commands with ulimit\n    match:  (ctx) => ctx.tool === 'Bash' && \u002Frm|chmod|chown\u002F.test(String(ctx.args.command ?? '')),\n    mutate: (ctx) => {\n      const MAX_MEM_KB = process.env.YAMTAM_TOOL_MAX_MEM ?? '524288'  \u002F\u002F 512MB\n      ctx.args = {\n        ...ctx.args,\n        command: `ulimit -v ${MAX_MEM_KB}; ${ctx.args.command}`,\n      }\n      return ctx\n    },\n  },\n]\n\nfunction applyMutations(ctx: ToolContext): ToolContext {\n  for (const rule of MUTATION_RULES) {\n    if (rule.match(ctx)) ctx = rule.mutate(ctx)\n  }\n  return ctx\n}\n\n\u002F\u002F Rule: mutate BEFORE block — give the command a chance to become safe\n\u002F\u002F Rule: all mutations must be logged to audit trail (what was added and why)\n\u002F\u002F Rule: mutation rules checked in order — first match wins (caddy matchers)\n```\n\n---\n\n## Shell Proxy: tool-proxy.sh\n\nThe companion script at `core\u002Fscripts\u002Ftool-proxy.sh` — run every Bash tool call through it:\n\n```bash\n# Usage: bash core\u002Fscripts\u002Ftool-proxy.sh \u003Ccommand> [args...]\n# Returns: exit 0 = safe + executed; exit 3 = sanitize block; exit 1 = mutate block\n\nYAMTAM_TOOL_TIMEOUT=30\nYAMTAM_TOOL_MAX_MEM=524288   # 512MB in KB\n\nbash core\u002Fscripts\u002Ftool-proxy.sh \"ls -la \u002Ftmp\"\nbash core\u002Fscripts\u002Ftool-proxy.sh \"git diff HEAD\"\n# Blocked: bash core\u002Fscripts\u002Ftool-proxy.sh \"cat file | bash\"  ← exit 3\n# Mutated: bash core\u002Fscripts\u002Ftool-proxy.sh \"rm -rf \u002Ftmp\u002Fx\"   ← ulimit added\n```\n\nSee full implementation: `core\u002Fscripts\u002Ftool-proxy.sh`\n\n---\n\n## Phase 4 — Pipe-Through (piping-server pattern)\n\n```typescript\n\u002F\u002F piping-server insight: stream data process-to-process via HTTP pipe\n\u002F\u002F No disk write — data flows in-memory. Useful for large tool results.\n\nimport { Transform } from 'stream'\n\nclass ToolResultPipe extends Transform {\n  #scanned = 0\n  readonly #maxBytes = 16 * 1024\n\n  _transform(chunk: Buffer, _enc: string, cb: (err: Error | null, data?: Buffer) => void) {\n    this.#scanned += chunk.length\n    if (this.#scanned > this.#maxBytes) {\n      this.push(Buffer.from('\\n[TRUNCATED — 16KB cap]\\n'))\n      this.end()\n      cb(null)\n      return\n    }\n    \u002F\u002F In-flight PII scan on streaming chunk — no buffering to disk\n    const clean = chunk.toString().replace(\u002FBearer [A-Za-z0-9._-]+\u002Fg, '[REDACTED]')\n    cb(null, Buffer.from(clean))\n  }\n}\n\n\u002F\u002F Pipe tool stdout through sanitize transform in-memory\nasync function pipedToolExec(cmd: string): Promise\u003Cstring> {\n  const { stdout } = await execAsync(cmd)\n  const pipe = new ToolResultPipe()\n  return new Promise((resolve, reject) => {\n    const chunks: Buffer[] = []\n    pipe.on('data', c => chunks.push(c))\n    pipe.on('end', () => resolve(Buffer.concat(chunks).toString()))\n    pipe.on('error', reject)\n    pipe.end(Buffer.from(stdout))\n  })\n}\n\n\u002F\u002F Rule: never write raw tool output to disk — pipe through sanitize transform\n\u002F\u002F Rule: streaming PII scan prevents large-result buffering in memory\n```\n\n---\n\n## Express Scope: Global vs Tool-Specific Middleware\n\n```typescript\n\u002F\u002F Express insight: global middleware vs router-scoped — apply the same here\n\n\u002F\u002F Global: every tool call\ntoolRouter.use(interceptLayer)        \u002F\u002F all tools\ntoolRouter.use(sanitizeLayer)         \u002F\u002F all tools\n\n\u002F\u002F Tool-specific: only Bash gets mutate layer (file tools don't need ulimit)\ntoolRouter.tool('Bash', mutateLayer)\ntoolRouter.tool('Bash', resourceCapLayer)\n\n\u002F\u002F Error middleware (always last — 4-arg signature)\ntoolRouter.use((err: Error, ctx: ToolContext, next: Next) => {\n  auditLog.error({ tool: ctx.tool, err: err.message, gate: (err as any).gate })\n  \u002F\u002F Do NOT re-throw — error middleware terminates the chain\n})\n\n\u002F\u002F Rule: error middleware must be LAST in the chain\n\u002F\u002F Rule: tool-specific middleware reduces blast radius vs applying everything globally\n```\n\n---\n\n## Anti-Fake-Pass Checklist\n\n```\n❌ next() called after interceptor already threw (double-dispatch crash)\n❌ Sanitize strips chars but doesn't re-validate after strip (second-order injection)\n❌ Mutate adds ulimit but doesn't log the mutation to audit trail\n❌ Response interceptor missing — raw tool output with PII returned to agent\n❌ Pipe writes to \u002Ftmp instead of in-memory transform (disk trace left behind)\n❌ Global middleware applied to file-read tools (ulimit on Read = wasted overhead)\n❌ Error middleware not last — subsequent middleware never sees the error\n❌ auto-quote-vars interceptor modifies URL args (breaks curl with $HOSTNAME in URL)\n```\n","# \u002Fintercept-layer\n\n## When to Use\n\n- Every agent tool call must pass through intercept → sanitize → mutate → execute\n- \"The agent ran a command with unsafe params — how do we catch it before exec?\"\n- Need to auto-harden a command (add timeout, resource cap) instead of just blocking it\n- Pipeline needs layers that act both before AND after execution (onion model)\n\n## Do NOT use for\n\n- In-process function calls with no shell\u002Fexec boundary\n- Read-only introspection (no mutation needed)\n\n---\n\n## Architecture: Four-Phase Proxy Pipeline\n\n```\nAgent emits tool call\n       │\n       ▼\n┌──────────────────────────────────────────┐\n│  PHASE 1 — INTERCEPT                     │\n│  Read raw command + args, log to audit   │\n│  Source: koa onion — outer layer entry   │\n└──────────────────┬───────────────────────┘\n                   │\n                   ▼\n┌──────────────────────────────────────────┐\n│  PHASE 2 — SANITIZE  (Gate L2)           │\n│  Strip injection chars (; | & ` $())     │\n│  Auto-quote bare variables               │\n│  Block subshell escape ($() \u003C() `)       │\n│  Source: axios request interceptor       │\n└──────────────────┬───────────────────────┘\n                   │ clean args\n                   ▼\n┌──────────────────────────────────────────┐\n│  PHASE 3 — MUTATE  (Gate L1)             │\n│  Auto-add missing safety config:         │\n│    • timeout wrapper                     │\n│    • ulimit memory cap                   │\n│    • network flag if missing             │\n│  Source: caddy handler chain mutation    │\n└──────────────────┬───────────────────────┘\n                   │ hardened command\n                   ▼\n           [tool executes]\n                   │\n                   ▼\n┌──────────────────────────────────────────┐\n│  PHASE 4 — RESPONSE INTERCEPT  (Gate L0) │\n│  Sanitize output (strip PII \u002F secrets)   │\n│  Cap result size (16KB)                  │\n│  Audit log result hash                   │\n│  Source: axios response interceptor      │\n└──────────────────────────────────────────┘\n```\n\n---\n\n## Phase 1 — Onion Composition (koa pattern)\n\n```typescript\n\u002F\u002F Koa's compose() — each middleware wraps the next layer\n\u002F\u002F Before-call logic runs top-down; after-call logic runs bottom-up\ntype Next = () => Promise\u003Cvoid>\ntype Middleware = (ctx: ToolContext, next: Next) => Promise\u003Cvoid>\n\nfunction compose(middlewares: Middleware[]) {\n  return function (ctx: ToolContext): Promise\u003Cvoid> {\n    let index = -1\n\n    function dispatch(i: number): Promise\u003Cvoid> {\n      if (i \u003C= index) return Promise.reject(new Error('next() called multiple times'))\n      index = i\n      const fn = middlewares[i]\n      if (!fn) return Promise.resolve()  \u002F\u002F end of chain → execute tool\n      return Promise.resolve(fn(ctx, () => dispatch(i + 1)))\n    }\n\n    return dispatch(0)\n  }\n}\n\n\u002F\u002F Usage: wrap any layer — PRE logic runs before next(), POST logic after\nconst interceptLayer: Middleware = async (ctx, next) => {\n  ctx.interceptedAt = Date.now()\n  auditLog.record({ phase: 'intercept', tool: ctx.tool, args: ctx.args })\n\n  await next()  \u002F\u002F ← inner layers run here\n\n  \u002F\u002F POST: runs after tool execution and all inner layers complete\n  auditLog.record({ phase: 'result', tool: ctx.tool, elapsed: Date.now() - ctx.interceptedAt })\n}\n\n\u002F\u002F Rule: compose() order = outermost first, innermost = actual execute\n\u002F\u002F Rule: never call next() twice in the same middleware — throws\n```\n\n---\n\n## Phase 2 — Sanitize (axios interceptor pattern)\n\n```typescript\n\u002F\u002F Axios-style: register named interceptors that can mutate or reject\nclass InterceptorManager\u003CT> {\n  #handlers: Array\u003C{ name: string; fn: (v: T) => T | Promise\u003CT> }> = []\n\n  use(name: string, fn: (v: T) => T | Promise\u003CT>) {\n    this.#handlers.push({ name, fn })\n    return this  \u002F\u002F chainable\n  }\n\n  async run(value: T): Promise\u003CT> {\n    let current = value\n    for (const { name, fn } of this.#handlers) {\n      current = await fn(current)\n    }\n    return current\n  }\n}\n\n\u002F\u002F Request (pre-exec) interceptors\nconst requestInterceptors = new InterceptorManager\u003CToolContext>()\n\nrequestInterceptors\n  .use('strip-injection-chars', (ctx) => {\n    const INJECTION_CHARS = \u002F[;&|`$>\u003C\\n]\u002Fg\n    ctx.args = Object.fromEntries(\n      Object.entries(ctx.args).map(([k, v]) => [\n        k,\n        typeof v === 'string' ? v.replace(INJECTION_CHARS, '') : v,\n      ])\n    )\n    return ctx\n  })\n  .use('block-subshell', (ctx) => {\n    const SUBSHELL = \u002F\\$\\(|\\`|\u003C\\(\u002F\n    const raw = JSON.stringify(ctx.args)\n    if (SUBSHELL.test(raw)) {\n      throw Object.assign(new Error('subshell escape attempt in args'), { gate: 'L2', exitCode: 3 })\n    }\n    return ctx\n  })\n  .use('auto-quote-vars', (ctx) => {\n    \u002F\u002F Bare $VAR in string args → \"${VAR}\" to prevent word splitting\n    ctx.args = Object.fromEntries(\n      Object.entries(ctx.args).map(([k, v]) => [\n        k,\n        typeof v === 'string' ? v.replace(\u002F\\$([A-Za-z_][A-Za-z0-9_]*)\u002Fg, '\"$${$1}\"') : v,\n      ])\n    )\n    return ctx\n  })\n\n\u002F\u002F Response interceptors — post-exec output sanitize\nconst responseInterceptors = new InterceptorManager\u003CToolContext>()\n\nresponseInterceptors\n  .use('strip-pii', (ctx) => {\n    if (ctx.result) ctx.result = piiScrub(ctx.result)\n    return ctx\n  })\n  .use('size-cap', (ctx) => {\n    const MAX = 16 * 1024\n    if (ctx.result && ctx.result.length > MAX) {\n      ctx.result = ctx.result.slice(0, MAX) + '\\n[TRUNCATED]'\n    }\n    return ctx\n  })\n\n\u002F\u002F Rule: interceptors run in registration order — security checks must be first\n\u002F\u002F Rule: throw to abort pipeline; return mutated ctx to continue\n```\n\n---\n\n## Phase 3 — Mutate (caddy handler chain pattern)\n\n```typescript\n\u002F\u002F Caddy insight: match → handler chain → upstream\n\u002F\u002F Mutation adds missing safety config BEFORE exec, not just block\u002Freject\n\ninterface MutationRule {\n  match:  (ctx: ToolContext) => boolean\n  mutate: (ctx: ToolContext) => ToolContext\n}\n\nconst MUTATION_RULES: MutationRule[] = [\n  {\n    \u002F\u002F Auto-add timeout if not present\n    match:  (ctx) => ctx.tool === 'Bash' && !ctx.args.timeout,\n    mutate: (ctx) => {\n      ctx.args = { ...ctx.args, timeout: Number(process.env.YAMTAM_TOOL_TIMEOUT ?? 30000) }\n      return ctx\n    },\n  },\n  {\n    \u002F\u002F Auto-add --no-network for file-only operations\n    match:  (ctx) => ctx.tool === 'Read' && !(ctx.args as any).url,\n    mutate: (ctx) => {\n      ;(ctx.args as any).__networkBlocked = true\n      return ctx\n    },\n  },\n  {\n    \u002F\u002F Auto-wrap destructive Bash commands with ulimit\n    match:  (ctx) => ctx.tool === 'Bash' && \u002Frm|chmod|chown\u002F.test(String(ctx.args.command ?? '')),\n    mutate: (ctx) => {\n      const MAX_MEM_KB = process.env.YAMTAM_TOOL_MAX_MEM ?? '524288'  \u002F\u002F 512MB\n      ctx.args = {\n        ...ctx.args,\n        command: `ulimit -v ${MAX_MEM_KB}; ${ctx.args.command}`,\n      }\n      return ctx\n    },\n  },\n]\n\nfunction applyMutations(ctx: ToolContext): ToolContext {\n  for (const rule of MUTATION_RULES) {\n    if (rule.match(ctx)) ctx = rule.mutate(ctx)\n  }\n  return ctx\n}\n\n\u002F\u002F Rule: mutate BEFORE block — give the command a chance to become safe\n\u002F\u002F Rule: all mutations must be logged to audit trail (what was added and why)\n\u002F\u002F Rule: mutation rules checked in order — first match wins (caddy matchers)\n```\n\n---\n\n## Shell Proxy: tool-proxy.sh\n\nThe companion script at `core\u002Fscripts\u002Ftool-proxy.sh` — run every Bash tool call through it:\n\n```bash\n# Usage: bash core\u002Fscripts\u002Ftool-proxy.sh \u003Ccommand> [args...]\n# Returns: exit 0 = safe + executed; exit 3 = sanitize block; exit 1 = mutate block\n\nYAMTAM_TOOL_TIMEOUT=30\nYAMTAM_TOOL_MAX_MEM=524288   # 512MB in KB\n\nbash core\u002Fscripts\u002Ftool-proxy.sh \"ls -la \u002Ftmp\"\nbash core\u002Fscripts\u002Ftool-proxy.sh \"git diff HEAD\"\n# Blocked: bash core\u002Fscripts\u002Ftool-proxy.sh \"cat file | bash\"  ← exit 3\n# Mutated: bash core\u002Fscripts\u002Ftool-proxy.sh \"rm -rf \u002Ftmp\u002Fx\"   ← ulimit added\n```\n\nSee full implementation: `core\u002Fscripts\u002Ftool-proxy.sh`\n\n---\n\n## Phase 4 — Pipe-Through (piping-server pattern)\n\n```typescript\n\u002F\u002F piping-server insight: stream data process-to-process via HTTP pipe\n\u002F\u002F No disk write — data flows in-memory. Useful for large tool results.\n\nimport { Transform } from 'stream'\n\nclass ToolResultPipe extends Transform {\n  #scanned = 0\n  readonly #maxBytes = 16 * 1024\n\n  _transform(chunk: Buffer, _enc: string, cb: (err: Error | null, data?: Buffer) => void) {\n    this.#scanned += chunk.length\n    if (this.#scanned > this.#maxBytes) {\n      this.push(Buffer.from('\\n[TRUNCATED — 16KB cap]\\n'))\n      this.end()\n      cb(null)\n      return\n    }\n    \u002F\u002F In-flight PII scan on streaming chunk — no buffering to disk\n    const clean = chunk.toString().replace(\u002FBearer [A-Za-z0-9._-]+\u002Fg, '[REDACTED]')\n    cb(null, Buffer.from(clean))\n  }\n}\n\n\u002F\u002F Pipe tool stdout through sanitize transform in-memory\nasync function pipedToolExec(cmd: string): Promise\u003Cstring> {\n  const { stdout } = await execAsync(cmd)\n  const pipe = new ToolResultPipe()\n  return new Promise((resolve, reject) => {\n    const chunks: Buffer[] = []\n    pipe.on('data', c => chunks.push(c))\n    pipe.on('end', () => resolve(Buffer.concat(chunks).toString()))\n    pipe.on('error', reject)\n    pipe.end(Buffer.from(stdout))\n  })\n}\n\n\u002F\u002F Rule: never write raw tool output to disk — pipe through sanitize transform\n\u002F\u002F Rule: streaming PII scan prevents large-result buffering in memory\n```\n\n---\n\n## Express Scope: Global vs Tool-Specific Middleware\n\n```typescript\n\u002F\u002F Express insight: global middleware vs router-scoped — apply the same here\n\n\u002F\u002F Global: every tool call\ntoolRouter.use(interceptLayer)        \u002F\u002F all tools\ntoolRouter.use(sanitizeLayer)         \u002F\u002F all tools\n\n\u002F\u002F Tool-specific: only Bash gets mutate layer (file tools don't need ulimit)\ntoolRouter.tool('Bash', mutateLayer)\ntoolRouter.tool('Bash', resourceCapLayer)\n\n\u002F\u002F Error middleware (always last — 4-arg signature)\ntoolRouter.use((err: Error, ctx: ToolContext, next: Next) => {\n  auditLog.error({ tool: ctx.tool, err: err.message, gate: (err as any).gate })\n  \u002F\u002F Do NOT re-throw — error middleware terminates the chain\n})\n\n\u002F\u002F Rule: error middleware must be LAST in the chain\n\u002F\u002F Rule: tool-specific middleware reduces blast radius vs applying everything globally\n```\n\n---\n\n## Anti-Fake-Pass Checklist\n\n```\n❌ next() called after interceptor already threw (double-dispatch crash)\n❌ Sanitize strips chars but doesn't re-validate after strip (second-order injection)\n❌ Mutate adds ulimit but doesn't log the mutation to audit trail\n❌ Response interceptor missing — raw tool output with PII returned to agent\n❌ Pipe writes to \u002Ftmp instead of in-memory transform (disk trace left behind)\n❌ Global middleware applied to file-read tools (ulimit on Read = wasted overhead)\n❌ Error middleware not last — subsequent middleware never sees the error\n❌ auto-quote-vars interceptor modifies URL args (breaks curl with $HOSTNAME in URL)\n```\n",{},"main","481dcd7dd2e288b9d627a2bd017db70e64e6c6fa",".claude\u002Fskills\u002Fagent-middleware-gate",2,"https:\u002F\u002Fgithub.com\u002FHoronomos-laps\u002FYana-AI","https:\u002F\u002Fyana.vutam.link\u002F","https:\u002F\u002Fgithub.com\u002FHoronomos-laps","https:\u002F\u002Fyana.vutam.link","An open-source governed runtime & execution environment for multi-agent AI systems.","2026-11-14 13:24:09",{"source":7,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add Horonomos-laps\u002FYana-AI --skill agent-middleware-gate",{"tool":39,"command":40},"bunx","bunx skills add Horonomos-laps\u002FYana-AI --skill agent-middleware-gate",{"tool":42,"command":43},"pnpm","pnpm dlx skills add Horonomos-laps\u002FYana-AI --skill agent-middleware-gate","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FHoronomos-laps\u002FYana-AI\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fagent-middleware-gate\u002FSKILL.md",true,[],[48,56,63,71,79,87],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":52,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":18},"01M735GKET5YVYKAY62W2P5YXB","openai--sentry--sentry","Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.","MIT","https:\u002F\u002Fgithub.com\u002FHoronomos-laps\u002FYana-AI\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fopenai--sentry--sentry\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":59,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":18},"01M73DCAP83T17HY7SMGK7MGFE","ito-basket-compare","Compare Itô prediction-market baskets against a user's knowledge base, portfolio notes, financial context, watchlist, or research thesis. Use for read-only basket comparison and gap analysis without investment advice or live trading.","https:\u002F\u002Fgithub.com\u002FHoronomos-laps\u002FYana-AI\u002Fblob\u002Fmain\u002Fcore\u002Fskills\u002Fito-basket-compare\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":67,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":18},"01M734CYEMZFDR3KH6SW0JP8TD","implementing-network-traffic-baselining","Build network traffic baselines from NetFlow\u002FIPFIX data using Python pandas for statistical analysis, z-score anomaly detection, and hourly\u002Fdaily traffic pattern profiling","https:\u002F\u002Fgithub.com\u002Fyanacuti1121\u002FYana-AI\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fimplementing-network-traffic-baselining\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FHoronomos-laps\u002FYana-AI\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fimplementing-network-traffic-baselining\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":75,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":18},"01M73ASZ6NJRJM44Z2P84NGQ3Q","detecting-evasion-techniques-in-endpoint-logs","Detects defense evasion techniques used by adversaries in endpoint logs including log tampering, timestomping, process injection, and security tool disabling. Use when investigating suspicious endpoint behavior, building detection rules for evasion tactics, or conducting threat hunting for stealthy adversary activity. Activates for requests involving evasion detection, defense evasion analysis, log tampering detection, or MITRE ATT&CK TA0005.","https:\u002F\u002Fgithub.com\u002Fyanacuti1121\u002FYana-AI\u002Fblob\u002Fmain\u002Fcore\u002Fskills\u002Fdetecting-evasion-techniques-in-endpoint-logs\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FHoronomos-laps\u002FYana-AI\u002Fblob\u002Fmain\u002Fcore\u002Fskills\u002Fdetecting-evasion-techniques-in-endpoint-logs\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":83,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":18},"01M734AFNXD06Z78QRK0VKGT7Q","implementing-microsegmentation-with-guardicore","Implementing microsegmentation using Akamai Guardicore Segmentation to map application dependencies, create granular network policies, visualize east-west traffic flows, and enforce least-privilege communication between workloads across data centers and cloud.","https:\u002F\u002Fgithub.com\u002Fyanacuti1121\u002FYana-AI\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fimplementing-microsegmentation-with-guardicore\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FHoronomos-laps\u002FYana-AI\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fimplementing-microsegmentation-with-guardicore\u002FSKILL.md",[],[],{"skillNo":88,"name":89,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":18},"01M736TK27QMCXK0DVCH25SJN5","ramdisk-tmpfs-patterns","https:\u002F\u002Fgithub.com\u002FHoronomos-laps\u002FYana-AI\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Framdisk-tmpfs-patterns\u002FSKILL.md",[],[]]