# 你是什么 AI 人格 Instructions

You are helping the user generate an AI personality report from local Codex runtime aggregates.

## Privacy Boundary

Use aggregate numbers only. Do not include raw rollout JSONL, prompts, chat content, file paths, command output, secrets, tokens, API keys, or project names in the report link.

This site is static. Do not POST data to the site. Generate a browser-only report URL with fragment data:

```text
<site-origin>/report#data=<base64url-json>
```

The fragment after `#` is handled locally by the user's browser and is not sent to the server in normal HTTP requests.

## Payload Schema

Send JSON with these fields:

```json
{
  "totalTokens": 10833316431,
  "reasoningTokens": 9984605,
  "outputTokens": 30888277,
  "toolCalls": 106361,
  "uniqueTools": 40,
  "threadCount": 335,
  "avgThreadTokens": 32338258,
  "maxThreadTokens": 628936290,
  "threadsWithTokenCount": 326
}
```

Required fields: `totalTokens`, `reasoningTokens`, `outputTokens`, `toolCalls`, `uniqueTools`, `threadCount`, `maxThreadTokens`.

Optional fields: `avgThreadTokens`, `threadsWithTokenCount`.

## Collection Guidance

Prefer the official Codex profile at:

- `$HOME/.codex/state_5.sqlite`

The `threads` table contains `tokens_used` and `rollout_path`. For each rollout JSONL, use the last `event_msg` whose payload type is `token_count` to read `total_token_usage.reasoning_output_tokens` and `total_token_usage.output_tokens`.

Count actual tool calls by scanning rollout JSONL `response_item` events where payload type is `function_call` or `tool_search_call`.

Recommended shell outline:

```bash
DB="$HOME/.codex/state_5.sqlite"

threadCount=$(sqlite3 "$DB" "select count(*) from threads;")
totalTokens=$(sqlite3 "$DB" "select coalesce(sum(tokens_used),0) from threads;")
maxThreadTokens=$(sqlite3 "$DB" "select coalesce(max(tokens_used),0) from threads;")
avgThreadTokens=$(sqlite3 "$DB" "select round(coalesce(avg(tokens_used),0)) from threads;")

sqlite3 -noheader "$DB" "select rollout_path from threads where rollout_path is not null and rollout_path != '';" |
while IFS= read -r p; do
  if [ -f "$p" ]; then
    jq -r '
      select(.type=="event_msg" and .payload.type=="token_count")
      | .payload.info.total_token_usage
      | select(.reasoning_output_tokens | type=="number")
      | select(.output_tokens | type=="number")
      | [.reasoning_output_tokens, .output_tokens]
      | @tsv
    ' "$p" | tail -n 1
  fi
done |
awk 'NF{n++; reasoning+=$1; output+=$2} END{printf "threadsWithTokenCount=%d\nreasoningTokens=%0.0f\noutputTokens=%0.0f\n", n, reasoning, output}'

sqlite3 -noheader "$DB" "select rollout_path from threads where rollout_path is not null and rollout_path != '';" |
while IFS= read -r p; do
  if [ -f "$p" ]; then
    jq -r 'select(.type=="response_item" and (.payload.type=="function_call" or .payload.type=="tool_search_call")) | if .payload.type=="function_call" then .payload.name else .payload.type end' "$p"
  fi
done |
awk '{total++; tools[$0]=1} END{printf "toolCalls=%d\nuniqueTools=%d\n", total, length(tools)}'
```

If `jq` or `sqlite3` is unavailable, use another local parser. Keep the same privacy boundary.

## Generate Report URL

After computing the aggregate JSON, save it to `/tmp/codex-type-stats.json`, create a payload with `schemaVersion`, `createdAt`, and `stats`, then base64url encode it and build the report URL.

Set `SITE_ORIGIN` to the exact origin of the website URL the user gave you, for example `https://codex-type.example`. Do not use a placeholder origin.

```bash
export SITE_ORIGIN="https://codex-type.example"

node <<'NODE'
const fs = require("node:fs");
const stats = JSON.parse(fs.readFileSync("/tmp/codex-type-stats.json", "utf8"));
const siteOrigin = process.env.SITE_ORIGIN;

if (!siteOrigin) {
  throw new Error("Set SITE_ORIGIN to the origin of the website URL the user provided.");
}

const payload = {
  schemaVersion: 1,
  createdAt: new Date().toISOString(),
  stats
};

const token = Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
console.log(`${new URL(siteOrigin).origin}/report#data=${token}`);
NODE
```

Return the report URL to the user. You may also summarize the aggregate stats in chat, but do not include raw runtime content.
