Inspecting agents
Result: a read-only report that answers each question with the command that produced it and the field the answer came from. Nothing is created, voted on, or deleted.
Each question below is one tk list narrowed by its filter flags plus a
jq projection; jq selects only where no flag exists (the tag-id search
over policies, the public-key join that attributes a mint). Each answer
states its provenance: the command, the pages read, and the field.
Reference
- resources:
user listtag filtering,user tagrecords,api-key listowner selection and expiry modes, andpolicyrecords. - activities:
activity listfiltering and paging, andactivity get. - secrets:
secret listfiltering.
Rules
- Read only. Approving, rejecting, or waiting on what you find belongs to monitoring-activities.
- Page to the end before answering "none".
activity listpages with--limitand--cursor; a page is the last one whendata.nextCursorisnull. A filteredsecret listpages the same way; see secrets.user list,user tag list,policy list, andapi-key listreturn everything in one response. user list --tagtakes a tag name or id. Policy text carries tag ids, not names, so step 7 resolves the name once withuser tag list.expiresAton an API key is a Unix-millisecond string, ornullfor a key that never expires. On the session route the anchor is the only permanent key an agent should hold; on the long-lived route the one runtime key is permanent.- Who minted a key is a join, never a guess: the key's
credential.publicKeyagainst thepublicKeyinside an activity'sintent(createApiKeysIntentV2.apiKeys[]orcreateUsersIntentV4.users[].apiKeys[]). When no activity in the pages you traversed matches, the answer is "unknown". Do not infer a minter from voters on other activities. - A textual search of policy
consensusandconditionfor a tag id or user id is a candidate list, not a parsed dependency graph. Read each candidate before claiming it governs the tag or user.
Instructions
Inputs: any profile in the organization (admin below), and the tag names
or ids the question is about. Every command below prints one JSON record;
jq selects from it.
Resolve tag ids.
<!-- example: inspecting.tags -->tk --profile admin --message-format json user tag list | jq -r '.data.userTags[] | "\(.tagId) \(.tagName)"' AGENT_TAG=$(tk --profile admin --message-format json user tag list | jq -r '.data.userTags[] | select(.tagName == "agent") | .tagId')data.userTags[]carriestagId,tagName, anduserIds. Step 7 uses$AGENT_TAG; step 2 takes the name directly. A name that matches nothing leaves the variable empty; stop and report that, do not fall back to a substring match.Which users carry a tag.
<!-- example: inspecting.tagged-users -->tk --profile admin --message-format json user list --tag agent | jq '.data.users[] | {userId, userName}'The list is complete in one response.
Which keys an agent holds and when they expire.
<!-- example: inspecting.keys -->tk --profile admin --message-format json api-key list --user-id AGENT_USER_ID | jq '.data.apiKeys[] | {apiKeyId, apiKeyName, publicKey: .credential.publicKey, expiresAt}' tk --profile admin --message-format json api-key list --all-users --long-lived | jq -r '.data.apiKeys[] | "\(.userId) \(.apiKeyId)"' tk --profile admin --message-format json api-key list --all-users --expiring-within 24h | jq -r '.data.apiKeys[] | "\(.userId) \(.apiKeyId) \(.expiresAt)"'The first command reads one user from step 2. The second lists every permanent key by owner: a session-route agent should own exactly one, its anchor; more than one is a finding. The third lists keys that expire within the window; see resources for the expiry modes.
What is pending and for how long.
<!-- example: inspecting.pending -->tk --profile admin --message-format json activity list --status pending --limit 50 | jq --arg now "$(date +%s)" '.data.items[] | {id, type, status, ageSeconds: (($now | tonumber) - (.createdAt.seconds | tonumber))}'
<!-- example: inspecting.next-page -->data.items[]is one page, newest first;createdAt.secondsis a Unix-second string. Continue with the cursor until it printsnull:NEXT_ACTIVITY_ID=$(tk --profile admin --message-format json activity list --status pending --limit 50 | jq -r '.data.nextCursor') tk --profile admin --message-format json activity list --status pending --limit 50 --cursor $NEXT_ACTIVITY_ID | jq -r '.data.nextCursor'Concatenate the pages. A pending activity appears on exactly one page.
Who voted on an activity.
<!-- example: inspecting.votes -->tk --profile admin --message-format json activity get --id ACTIVITY_ID | jq '.data.activity.votes[] | {userId, selection}'selectionisVOTE_SELECTION_APPROVEDorVOTE_SELECTION_REJECTED. The submitter's own approval is the first vote; the missing approver is whoever the policy consensus names and this list does not.Which secrets carry which properties.
<!-- example: inspecting.secrets -->tk --profile admin --message-format json secret list --property env=prod | jq '.data.secrets[] | {name, properties: (.staticProperties | map("\(.key)=\(.value)"))}' tk --profile admin --message-format json secret list --name-prefix service/ --property env=prod | jq -r '.data.secrets[].name'staticProperties[]iskeyandvalue; values of the secrets themselves are never listed.Which policies mention a tag or user. Take the agent's
<!-- example: inspecting.policies -->userIdfrom step 2 into$AGENT_USER_ID; signing grants name the user, not the tag:tk --profile admin --message-format json policy list | jq --arg tag "$AGENT_TAG" --arg user "$AGENT_USER_ID" '.data.policies[] | select((.consensus // "") + (.condition // "") | contains($tag) or contains($user)) | {policyId, policyName, effect}'These are candidates. Read each one's
consensusandconditionto say whether the tag or user is an approver, a target, or both. An empty$AGENT_TAGor$AGENT_USER_IDmatches every policy; set both first.Who minted a key. Take the key's
<!-- example: inspecting.minted-by -->credential.publicKeyfrom step 3 into$KEY_PUBLIC_KEY, then join it against each page of the activities that can mint one:tk --profile admin --message-format json activity list --type 'ACTIVITY_TYPE_CREATE_API_KEYS_V2' --type 'ACTIVITY_TYPE_CREATE_USERS_V4' --limit 50 | jq --arg pk "$KEY_PUBLIC_KEY" '.data.items[] | select(any(.intent.createApiKeysIntentV2.apiKeys[]?, .intent.createUsersIntentV4.users[]?.apiKeys[]?; .publicKey == $pk)) | {id, type, status, minted: .createdAt.seconds, voters: [.votes[].userId]}'Page as in step 4, keeping both
--typeflags on every page; add--since 7dwhen the key is known to be recent. One match gives the activity and its voters, the first of which submitted it. No match across every page is "unknown". Empty output on the first page alone proves nothing.Hand off. One line per question: the answer, the command, the pages read (
1 of 1,3 of 3), and the field it came from. Pending ids, permanent-key findings, and "unknown" minters are listed explicitly. Stop.
Verified by
| Examples | Test |
|---|---|
| inspecting.tags, inspecting.tagged-users, inspecting.keys, inspecting.pending, inspecting.next-page, inspecting.votes, inspecting.secrets, inspecting.policies, inspecting.minted-by | users::inspecting_agents_jq_recipes_answer_live_records |
Troubleshooting
jq: command not found: installjq; every recipe here projects fields from the JSON record with it. Nothing intkdepends on it.user list --tag,user get, orapi-key listfails withnot_found: the tag name or user id belongs to another organization or was mistyped. Check--profileand the id from step 2.- Step 1 leaves
$AGENT_TAGempty: the tag name is different in this organization. Read the fulluser tag listoutput and pick the id by hand; do not guess from a similar name. - A page has zero items but the previous page had a cursor: the previous
page was exactly
--limitlong. That empty page is the end. activity list --status pendingshows nothing but a command reportedpending: the vote may have landed since.activity get --id ACTIVITY_IDshows the current status of that one activity.- Step 8 finds no match: widen the traversal to every page, and drop
--sinceif you added it, before saying "unknown"; an activity older than the pages read is not evidence of anything.
Related Skills
- monitoring-activities: approve, reject, or wait on what step 4 found.
- managing-identities: rotate or revoke a key that step 3 flagged.
- provisioning-session-agent: the expiring keys and anchor that step 3 reads.
- managing-policies: read or change the policies step 7 listed.