Skip to content

g1t/crates/contracts/src/credentials.rs

1,183 lines41,557 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API1//! Run credentials: the least-privilege tokens a sandbox works with.
2//!
3//! Every sandbox run gets its own tokens, bound to the run, its repository
4//! (and the pull request's fork), what that kind of run needs to do, and an
5//! expiry no later than the run's timeout. Each carries a composite
6//! identity: an agent acting on behalf of the person who started the work.
7//! What it may do is the intersection of the two: the run's scope, and what
8//! that person may do right now.
9//!
10//! The policy lives here, as pure functions, so that identity (which mints
11//! the tokens), the API (which serves REST and MCP) and repos (which serves
12//! git) all enforce the same rules, and so the rules can be tested.
13
14use serde::{Deserialize, Serialize};
15
16use crate::identity::AgentScope;
17use crate::repos::RepoPath;
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look18use crate::access::{BasePermission, RepoGrant, RepoRole};
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API19use crate::{Membership, PrincipalKind, Role, User};
20
21/// What a run does, as far as its credentials are concerned. The same names
22/// as [`crate::agents::RunKind`], plus `deploy`, a build of one commit.
23#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
24#[serde(rename_all = "snake_case")]
25pub enum RunCredentialKind {
26 Implement,
27 Revise,
28 Review,
29 Answer,
30 Update,
31 Plan,
32 Checks,
33 Queue,
34 Mergecheck,
35 Deploy,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily36 /// A security update: raising one package's version in its lockfiles
37 /// and pushing that to a branch of its own. Not an agent.
38 Bump,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API39}
40
41impl RunCredentialKind {
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily42 pub const ALL: [RunCredentialKind; 11] = [
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API43 RunCredentialKind::Implement,
44 RunCredentialKind::Revise,
45 RunCredentialKind::Review,
46 RunCredentialKind::Answer,
47 RunCredentialKind::Update,
48 RunCredentialKind::Plan,
49 RunCredentialKind::Checks,
50 RunCredentialKind::Queue,
51 RunCredentialKind::Mergecheck,
52 RunCredentialKind::Deploy,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily53 RunCredentialKind::Bump,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API54 ];
55
56 pub fn as_str(self) -> &'static str {
57 match self {
58 RunCredentialKind::Implement => "implement",
59 RunCredentialKind::Revise => "revise",
60 RunCredentialKind::Review => "review",
61 RunCredentialKind::Answer => "answer",
62 RunCredentialKind::Update => "update",
63 RunCredentialKind::Plan => "plan",
64 RunCredentialKind::Checks => "checks",
65 RunCredentialKind::Queue => "queue",
66 RunCredentialKind::Mergecheck => "mergecheck",
67 RunCredentialKind::Deploy => "deploy",
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily68 RunCredentialKind::Bump => "bump",
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API69 }
70 }
71
72 /// Whether the run works on one pull request, whose session and
73 /// readiness it reports.
74 fn works_on_a_pull(self) -> bool {
75 matches!(
76 self,
77 RunCredentialKind::Implement
78 | RunCredentialKind::Revise
79 | RunCredentialKind::Answer
80 | RunCredentialKind::Update
81 )
82 }
83}
84
85/// Which part of a sandbox a credential is for.
86#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
87#[serde(rename_all = "snake_case")]
88pub enum CredentialUse {
89 /// g1t's runner: cloning, pushing the result, recording the session.
90 /// It acts as the person downstream, so that what it pushes and records
91 /// is theirs, within the run's scope.
92 Runner,
93 /// The agent's own tools, over MCP. It acts as the agent.
94 Tools,
95}
96
97impl CredentialUse {
98 pub fn as_str(self) -> &'static str {
99 match self {
100 CredentialUse::Runner => "runner",
101 CredentialUse::Tools => "tools",
102 }
103 }
104}
105
106/// A repository a run may push to, and the one branch, if only one.
107#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
108pub struct GitGrant {
109 pub repo: RepoPath,
110 /// Null: any branch. A pull request's fork is its own repository, so
111 /// the whole of it is the pull request's.
112 #[serde(default)]
113 pub branch: Option<String>,
114}
115
116/// What binds an agent's token to one run. Absent on agent tokens made
117/// before run credentials, which keep working for the API only.
118#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
119#[serde(rename_all = "camelCase")]
120pub struct RunBinding {
121 pub kind: RunCredentialKind,
122 #[serde(rename = "use")]
123 pub usage: CredentialUse,
124 /// The agent run, once the sandbox has recorded it.
125 #[serde(default)]
126 pub run_id: Option<String>,
127 /// The pull request the run works on, for the kinds that work on one.
128 #[serde(default)]
129 pub number: Option<u32>,
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent130 /// The agent's name, such as `g1t`.
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API131 pub agent: String,
132 /// Repositories it may clone and fetch, besides those it may push to.
133 #[serde(default)]
134 pub read: Vec<RepoPath>,
135 /// Where it may push.
136 #[serde(default)]
137 pub push: Vec<GitGrant>,
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily138 /// g1t's own run (a security update, an agent g1t put on one): the
139 /// credential belongs to the workspace, and acts on behalf of g1t
140 /// (`system::ID`), so what it does is g1t's, and the pull request g1t
141 /// opened, and its working copy, are its own.
142 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
143 pub system: bool,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API144}
145
146/// A person, by id and name.
147#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
148pub struct Principal {
149 pub id: String,
150 pub username: String,
151}
152
g1t is the stored author of what it opens; the person who asked is requested_by and keeps the author's rights153impl From<&User> for Principal {
154 fn from(user: &User) -> Self {
155 Principal {
156 id: user.id.clone(),
157 username: user.username.clone(),
158 }
159 }
160}
161
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API162/// Set on a [`User`] resolved from an agent's token: the composite
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent163/// identity, "g1t on behalf of syntaqx", and what it may do.
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API164#[derive(Clone, Debug, Serialize, Deserialize)]
165#[serde(rename_all = "camelCase")]
166pub struct Acting {
167 /// The token's id, as audit entries name it.
168 pub credential_id: String,
169 pub agent: String,
170 pub on_behalf_of: Principal,
171 pub scope: AgentScope,
172}
173
174impl Acting {
175 pub fn run(&self) -> Option<&RunBinding> {
176 self.scope.run.as_ref()
177 }
178}
179
180/// `create_run_credential`: a token for one sandbox run. It acts as
181/// `agent` on behalf of `on_behalf_of`, can do only what `kind` and `usage`
182/// allow in `repo`, and expires after `ttl_seconds`, which should be the
183/// run's timeout. Returns `CreatedAccessToken`.
184#[derive(Clone, Debug, Serialize, Deserialize)]
185#[serde(rename_all = "camelCase")]
186pub struct CreateRunCredentialArgs {
187 pub on_behalf_of: User,
188 pub repo: RepoPath,
189 pub kind: RunCredentialKind,
190 #[serde(rename = "use")]
191 pub usage: CredentialUse,
192 #[serde(default)]
193 pub number: Option<u32>,
194 #[serde(default)]
195 pub read: Vec<RepoPath>,
196 #[serde(default)]
197 pub push: Vec<GitGrant>,
198 pub ttl_seconds: u64,
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent199 /// Defaults to `g1t`.
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API200 #[serde(default)]
201 pub agent: Option<String>,
202}
203
204/// `bind_run_credentials`: ties tokens, named by the SHA-256 of their
205/// text in hex, to the agent run their sandbox recorded. Returns how many.
206#[derive(Clone, Debug, Serialize, Deserialize)]
207#[serde(rename_all = "camelCase")]
208pub struct BindRunCredentialsArgs {
209 pub token_hashes: Vec<String>,
210 pub run_id: String,
211}
212
213/// `revoke_run_credentials`: ends tokens when their sandbox stops, by hash
214/// or by run. Only run credentials are touched, never a token a person
215/// made. Returns how many.
216#[derive(Clone, Debug, Default, Serialize, Deserialize)]
217#[serde(rename_all = "camelCase")]
218pub struct RevokeRunCredentialsArgs {
219 #[serde(default)]
220 pub token_hashes: Vec<String>,
221 #[serde(default)]
222 pub run_id: Option<String>,
223}
224
225// --- Policy --------------------------------------------------------------
226
227/// Operations that only read.
228pub const READ_OPERATIONS: &[&str] = &[
229 "whoami",
230 "list_repos",
231 "get_repo",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look232 "list_deleted_repos",
233 "list_collaborators",
234 "get_collaborator_permission",
235 "list_repo_invitations",
236 "list_my_repo_invitations",
237 "list_outside_collaborators",
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API238 "get_repo_settings",
Fast pages, required checks on the branch, self-hosted runners, honest incidents239 "list_check_names",
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API240 "get_merge_queue",
241 "recall",
242 "list_issues",
243 "get_issue",
244 "get_plan",
245 "list_labels",
246 "list_pull_requests",
247 "get_pull_request",
248 "read_session",
249 "get_pull_request_changes",
250 "list_events",
251 "get_context",
252 "search_context",
253 "get_entity",
Search across all of g1t, Explore, and a command palette254 "search",
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API255 "list_workflows",
256 "list_workflow_runs",
257 "get_workflow_run",
258 "get_job_logs",
259 "list_integrations",
260 "get_model_routes",
261 "list_webhooks",
262 "list_webhook_deliveries",
263 "list_actions_secrets",
264 "list_actions_variables",
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily265 "list_security_alerts",
API: notifications over REST and MCP, with notifications scopes266 "list_notifications",
267 "get_notification_thread",
268 "get_thread_subscription",
269 "get_repo_subscription",
270 "list_watched_repos",
API: pinned projects over REST and MCP271 "list_pinned_projects",
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API272];
273
274/// What no agent's token may ever do, whatever its scope says: workspaces,
275/// repositories' settings, members, tokens, billing, integrations,
276/// webhooks, secrets, workflows' controls, merging, and putting more agents
277/// to work.
278pub const NEVER: &[&str] = &[
279 "create_workspace",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look280 "delete_workspace",
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily281 "update_workspace",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look282 "transfer_repo",
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API283 "create_repo",
284 "update_repo",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look285 "delete_repo",
286 "list_deleted_repos",
287 "restore_repo",
288 "purge_repo",
289 "rename_repo",
290 "archive_repo",
291 "unarchive_repo",
292 "set_repo_visibility",
293 "rename_branch",
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API294 "update_repo_settings",
295 "merge_pull_request",
296 "assign_issue",
297 "plan_work",
298 "apply_plan",
299 "import_issue",
300 "list_integrations",
301 "connect_integration",
302 "disconnect_integration",
303 "test_integration",
304 "get_model_routes",
305 "set_model_routes",
306 "list_webhooks",
307 "create_webhook",
308 "update_webhook",
309 "delete_webhook",
310 "ping_webhook",
311 "list_webhook_deliveries",
312 "redeliver_webhook",
313 "dispatch_workflow",
314 "cancel_workflow_run",
315 "rerun_workflow_run",
316 "update_workflow",
317 "list_actions_secrets",
318 "set_actions_secret",
319 "delete_actions_secret",
320 "list_actions_variables",
321 "set_actions_variable",
322 "delete_actions_variable",
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look323 "list_collaborators",
324 "get_collaborator_permission",
325 "add_collaborator",
326 "update_collaborator",
327 "remove_collaborator",
328 "list_repo_invitations",
329 "revoke_repo_invitation",
330 "list_my_repo_invitations",
331 "accept_repo_invitation",
332 "decline_repo_invitation",
333 "set_base_permission",
334 "list_outside_collaborators",
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily335 // Dismissing a secret lets it through push protection.
336 "dismiss_security_alert",
337 "reopen_security_alert",
API: notifications over REST and MCP, with notifications scopes338 // A person's own inbox: g1t's agents act as g1t, which has none.
339 "list_notifications",
340 "get_notification_thread",
341 "mark_notifications_read",
342 "mark_thread_read",
343 "mark_thread_done",
344 "save_thread",
345 "snooze_thread",
346 "get_thread_subscription",
347 "set_thread_subscription",
348 "delete_thread_subscription",
349 "get_repo_subscription",
350 "set_repo_subscription",
351 "delete_repo_subscription",
352 "list_watched_repos",
API: pinned projects over REST and MCP353 // Pins are a person's own, as the inbox is.
354 "list_pinned_projects",
355 "pin_project",
356 "unpin_project",
357 "reorder_pinned_projects",
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API358];
359
360/// Reading what an agent needs to know about its repository.
361const TOOLS_READ: &[&str] = &[
362 "get_repo",
363 "list_issues",
364 "get_issue",
365 "list_labels",
366 "list_pull_requests",
367 "get_pull_request",
368 "get_pull_request_changes",
369 "read_session",
370 "get_merge_queue",
371 "list_events",
372 "recall",
373 "search_context",
374 "get_entity",
Search across all of g1t, Explore, and a command palette375 "search",
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API376 "list_workflows",
377 "list_workflow_runs",
378 "get_workflow_run",
379 "get_job_logs",
380];
381
382pub fn is_read(operation: &str) -> bool {
383 READ_OPERATIONS.contains(&operation)
384}
385
386/// The API and MCP operations a run of `kind` may use with a credential
387/// for `usage`. Git is separate: see [`decide_git`].
388pub fn operations_for(kind: RunCredentialKind, usage: CredentialUse) -> Vec<&'static str> {
389 use RunCredentialKind as K;
390 let mut operations: Vec<&'static str> = Vec::new();
391 match usage {
392 CredentialUse::Runner => {
393 if kind.works_on_a_pull() {
394 operations.extend(["get_repo", "get_pull_request", "record_session"]);
395 }
396 if kind == K::Implement {
397 operations.push("mark_pull_request_ready");
398 }
399 }
400 CredentialUse::Tools => match kind {
401 K::Implement | K::Revise | K::Answer => {
402 operations.extend(TOOLS_READ.iter().copied());
403 operations.extend([
404 "create_issue",
405 "add_comment",
406 "take_messages",
407 "remember",
408 "message_agent",
409 "answer_message",
410 "get_context",
411 ]);
412 }
413 K::Review => {
414 operations.extend(TOOLS_READ.iter().copied());
415 operations.extend(["add_comment", "review_pull_request", "get_context"]);
416 }
417 K::Plan => {
418 operations.extend(TOOLS_READ.iter().copied());
419 operations.extend(["create_issue", "get_context"]);
420 }
421 K::Update => operations.extend(TOOLS_READ.iter().copied()),
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily422 K::Checks | K::Queue | K::Mergecheck | K::Deploy | K::Bump => {}
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API423 },
424 }
425 operations
426}
427
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step428/// What a run's credential may do, in the scope vocabulary that access
429/// tokens use (see [`crate::scopes`]): the scopes of its operations, and
430/// for a runner, git's. Its operations, its repository and its run still
431/// bound it more tightly than these scopes say.
432pub fn run_scopes(kind: RunCredentialKind, usage: CredentialUse) -> Vec<crate::scopes::Scope> {
433 use crate::scopes::{Scope, normalize, scope_for};
434 let mut scopes: Vec<Scope> = operations_for(kind, usage)
435 .into_iter()
436 .filter_map(scope_for)
437 .collect();
438 if usage == CredentialUse::Runner {
439 scopes.push(Scope::CodeRead);
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily440 if matches!(
441 kind,
442 RunCredentialKind::Implement
443 | RunCredentialKind::Revise
444 | RunCredentialKind::Answer
445 | RunCredentialKind::Update
446 | RunCredentialKind::Bump
447 ) {
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step448 scopes.push(Scope::CodeWrite);
449 }
450 }
451 normalize(&mut scopes);
452 scopes
453}
454
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API455/// Operations that change a pull request, which a runner may do only to
456/// the pull request its run works on.
457const PULL_WRITES: &[&str] = &["record_session", "mark_pull_request_ready"];
458
459/// Whether something was allowed, and the rule that decided it.
460#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
461pub struct Decision {
462 pub allowed: bool,
463 /// A short, stable name: `run:implement/tools`, `never`,
464 /// `scope:repository` and so on. Shown in the audit log.
465 pub rule: String,
466 /// Why it was refused, for the caller.
467 #[serde(default, skip_serializing_if = "Option::is_none")]
468 pub reason: Option<String>,
469}
470
471impl Decision {
472 pub fn allow(rule: impl Into<String>) -> Self {
473 Decision {
474 allowed: true,
475 rule: rule.into(),
476 reason: None,
477 }
478 }
479
480 pub fn deny(rule: impl Into<String>, reason: impl Into<String>) -> Self {
481 Decision {
482 allowed: false,
483 rule: rule.into(),
484 reason: Some(reason.into()),
485 }
486 }
487}
488
489fn same_repo(a: &RepoPath, b: &RepoPath) -> bool {
490 a.namespace.eq_ignore_ascii_case(&b.namespace) && a.name.eq_ignore_ascii_case(&b.name)
491}
492
493fn scope_rule(scope: &AgentScope) -> String {
494 match &scope.run {
495 Some(run) => format!("run:{}/{}", run.kind.as_str(), run.usage.as_str()),
496 None => "agent-token".to_owned(),
497 }
498}
499
500/// Whether `user`, resolved from an agent's token with `scope`, may use
501/// `operation`. `repo` is the repository the call names, if any, and
502/// `needs_repo` whether the operation is about one; `number` the issue or
503/// pull request it names.
504pub fn decide_operation(
505 user: &User,
506 scope: &AgentScope,
507 operation: &str,
508 repo: Option<&RepoPath>,
509 needs_repo: bool,
510 number: Option<u32>,
511) -> Decision {
512 let who = "A g1t agent's token";
513 if NEVER.contains(&operation) {
514 return Decision::deny(
515 "never",
516 format!(
517 "{who} can never use {operation}: settings, members, tokens, billing, integrations, webhooks, secrets and merging are for people."
518 ),
519 );
520 }
521 if !scope.operations.iter().any(|name| name == operation) {
522 return Decision::deny(
523 "scope:operation",
524 format!("{who} for this run cannot use {operation}."),
525 );
526 }
527 if needs_repo && !repo.is_some_and(|asked| same_repo(asked, &scope.repo)) {
528 return Decision::deny(
529 "scope:repository",
530 format!(
531 "{who} works in {}/{} only.",
532 scope.repo.namespace, scope.repo.name
533 ),
534 );
535 }
536 // The intersection: the person it acts for must still be able to work
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look537 // in the repository's workspace, as a member or with a role on its
538 // repositories. What it may do in the repository itself is their
539 // role there, which services check (`access::can`).
540 if !crate::access::has_access_in(user, &scope.repo.namespace) {
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API541 return Decision::deny(
542 "on-behalf-of:membership",
543 format!(
544 "The person this agent works for is no longer a member of {}.",
545 scope.repo.namespace
546 ),
547 );
548 }
549 if let Some(run) = &scope.run
550 && run.usage == CredentialUse::Runner
551 && PULL_WRITES.contains(&operation)
552 && run.number.is_some()
553 && number != run.number
554 {
555 return Decision::deny(
556 "scope:pull",
557 format!(
558 "{who} can change pull request #{} only.",
559 run.number.unwrap_or_default()
560 ),
561 );
562 }
563 Decision::allow(scope_rule(scope))
564}
565
566/// Whether a run credential may clone or fetch (`write` false), or push to
567/// (`write` true), the repository at `repo`.
568pub fn decide_git(scope: &AgentScope, repo: &RepoPath, write: bool) -> Decision {
569 let Some(run) = scope
570 .run
571 .as_ref()
572 .filter(|run| run.usage == CredentialUse::Runner)
573 else {
574 return Decision::deny(
575 "git:not-a-run",
576 "A g1t agent's tools token cannot be used with git.",
577 );
578 };
579 let pushable = run.push.iter().any(|grant| same_repo(&grant.repo, repo));
580 if write {
581 return if pushable {
582 Decision::allow(format!("{}:push", scope_rule(scope)))
583 } else {
584 Decision::deny(
585 "git:push",
586 format!(
587 "A {} run cannot push to {}/{}.",
588 run.kind.as_str(),
589 repo.namespace,
590 repo.name
591 ),
592 )
593 };
594 }
595 let readable = pushable
596 || same_repo(&scope.repo, repo)
597 || run.read.iter().any(|path| same_repo(path, repo));
598 if readable {
599 Decision::allow(format!("{}:read", scope_rule(scope)))
600 } else {
601 Decision::deny(
602 "git:read",
603 format!(
604 "A {} run cannot read {}/{}.",
605 run.kind.as_str(),
606 repo.namespace,
607 repo.name
608 ),
609 )
610 }
611}
612
613/// Whether a push to `repo` is limited to certain branches, so that the
614/// refs it moves have to be read and checked with [`decide_refs`].
615pub fn limits_branches(scope: &AgentScope, repo: &RepoPath) -> bool {
616 scope
617 .run
618 .iter()
619 .flat_map(|run| run.push.iter())
620 .any(|grant| same_repo(&grant.repo, repo) && grant.branch.is_some())
621}
622
623/// Whether a push to `repo` may move `refs` (full refs, such as
624/// `refs/heads/main`). Tags are never a run's to move.
625pub fn decide_refs(scope: &AgentScope, repo: &RepoPath, refs: &[String]) -> Decision {
626 let repo_decision = decide_git(scope, repo, true);
627 if !repo_decision.allowed {
628 return repo_decision;
629 }
630 let grants: Vec<&GitGrant> = scope
631 .run
632 .iter()
633 .flat_map(|run| run.push.iter())
634 .filter(|grant| same_repo(&grant.repo, repo))
635 .collect();
636 for git_ref in refs {
637 let Some(branch) = git_ref.strip_prefix("refs/heads/") else {
638 return Decision::deny("git:ref", format!("A run cannot push {git_ref}."));
639 };
640 let allowed = grants
641 .iter()
642 .any(|grant| grant.branch.as_deref().is_none_or(|only| only == branch));
643 if !allowed {
644 return Decision::deny(
645 "git:ref",
646 format!(
647 "A run cannot push to {branch} in {}/{}.",
648 repo.namespace, repo.name
649 ),
650 );
651 }
652 }
653 repo_decision
654}
655
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look656/// The most an agent may be on a repository, whoever it works for: it
657/// can push, merge and run, never change settings or who has access.
658pub const AGENT_CEILING: RepoRole = RepoRole::Write;
659
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API660/// The memberships an agent working for `person` has: the run's
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look661/// workspace, as a member, only if the person is in it now, with the
662/// person's role on its repositories (an owner's Admin included) cut down
663/// to [`AGENT_CEILING`].
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API664pub fn intersect(person: &[Membership], namespace: &str) -> Vec<Membership> {
665 let namespace = namespace.to_lowercase();
666 person
667 .iter()
668 .filter(|membership| membership.slug == namespace)
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look669 .map(|membership| {
670 let base = match membership.role {
671 Role::Owner => BasePermission::Admin,
672 Role::Member => membership.base_permission.unwrap_or_default(),
673 };
674 Membership {
675 role: Role::Member,
676 base_permission: Some(match base {
677 BasePermission::Admin => BasePermission::Write,
678 base => base,
679 }),
680 ..membership.clone()
681 }
682 })
683 .collect()
684}
685
686/// The repository grants an agent working for `person` has: those in the
687/// run's workspace, each cut down to [`AGENT_CEILING`].
688pub fn intersect_grants(person: &[RepoGrant], namespace: &str) -> Vec<RepoGrant> {
689 let namespace = namespace.to_lowercase();
690 person
691 .iter()
692 .filter(|grant| grant.workspace == namespace)
693 .map(|grant| RepoGrant {
694 role: grant.role.min(AGENT_CEILING),
695 ..grant.clone()
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API696 })
697 .collect()
698}
699
700/// Who a runner's credential acts as downstream: the person, with only the
701/// agent's (already intersected) memberships. `None` for anything else.
702pub fn as_person(user: &User) -> Option<User> {
703 let acting = user.acting.as_ref()?;
704 if user.kind != PrincipalKind::Agent {
705 return None;
706 }
707 let run = acting.run()?;
708 if run.usage != CredentialUse::Runner {
709 return None;
710 }
711 Some(User {
712 id: acting.on_behalf_of.id.clone(),
713 username: acting.on_behalf_of.username.clone(),
714 kind: PrincipalKind::User,
715 verified: user.verified,
716 workspaces: user.workspaces.clone(),
717 avatar: None,
718 acting: None,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look719 grants: user.grants.clone(),
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step720 token: None,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API721 })
722}
723
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent724/// How an actor is described: "g1t on behalf of syntaqx".
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API725pub fn describe(user: &User) -> String {
726 match &user.acting {
727 Some(acting) => format!(
728 "{} on behalf of {}",
729 acting.agent, acting.on_behalf_of.username
730 ),
731 None => user.username.clone(),
732 }
733}
734
735#[cfg(test)]
736mod tests {
737 use super::*;
738
739 #[test]
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step740 fn a_run_s_scopes_are_never_admin() {
741 for kind in RunCredentialKind::ALL {
742 for usage in [CredentialUse::Runner, CredentialUse::Tools] {
743 let scopes = run_scopes(kind, usage);
744 assert!(scopes.iter().all(|scope| !scope.dangerous()), "{kind:?} {usage:?}: {scopes:?}");
745 }
746 }
747 let review = run_scopes(RunCredentialKind::Review, CredentialUse::Tools);
748 assert!(review.contains(&crate::scopes::Scope::PullRequestsWrite));
749 assert!(!review.contains(&crate::scopes::Scope::CodeWrite));
750 }
751
752 #[test]
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API753 fn agents_can_search_the_context_hub() {
754 for kind in [RunCredentialKind::Implement, RunCredentialKind::Review, RunCredentialKind::Plan] {
755 let tools = operations_for(kind, CredentialUse::Tools);
756 assert!(tools.contains(&"search_context") && tools.contains(&"get_entity"));
757 }
758 assert!(is_read("search_context") && is_read("get_entity"));
759 }
760
Search across all of g1t, Explore, and a command palette761 #[test]
762 fn agents_can_search_all_of_g1t() {
763 // Site-wide search only reads: every run that reads its repository
764 // may use it, and nothing that never reads gets it.
765 assert!(is_read("search"));
766 assert!(!NEVER.contains(&"search"));
767 for kind in [
768 RunCredentialKind::Implement,
769 RunCredentialKind::Revise,
770 RunCredentialKind::Answer,
771 RunCredentialKind::Review,
772 RunCredentialKind::Plan,
773 RunCredentialKind::Update,
774 ] {
775 let tools = operations_for(kind, CredentialUse::Tools);
776 assert!(tools.contains(&"search"), "{kind:?} should search");
777 // The context hub's search stays its own tool beside it.
778 assert!(tools.contains(&"search_context"), "{kind:?} keeps search_context");
779 }
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily780 for kind in [RunCredentialKind::Checks, RunCredentialKind::Queue, RunCredentialKind::Mergecheck, RunCredentialKind::Deploy, RunCredentialKind::Bump] {
Search across all of g1t, Explore, and a command palette781 assert!(!operations_for(kind, CredentialUse::Tools).contains(&"search"));
782 }
783 assert!(!operations_for(RunCredentialKind::Implement, CredentialUse::Runner).contains(&"search"));
784 }
785
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API786 fn path(namespace: &str, name: &str) -> RepoPath {
787 RepoPath {
788 namespace: namespace.to_owned(),
789 name: name.to_owned(),
790 }
791 }
792
793 fn scope(kind: RunCredentialKind, usage: CredentialUse) -> AgentScope {
794 AgentScope {
795 repo: path("acme", "rocket"),
796 operations: operations_for(kind, usage)
797 .into_iter()
798 .map(str::to_owned)
799 .collect(),
800 run: Some(RunBinding {
801 kind,
802 usage,
803 run_id: Some("run_1".to_owned()),
804 number: Some(7),
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent805 agent: "g1t".to_owned(),
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily806 system: false,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API807 read: vec![path("acme", "rocket")],
808 push: match kind {
809 RunCredentialKind::Implement
810 | RunCredentialKind::Revise
811 | RunCredentialKind::Answer => vec![GitGrant {
812 repo: path("pulls", "pul_7"),
813 branch: None,
814 }],
815 RunCredentialKind::Update => vec![GitGrant {
816 repo: path("acme", "rocket"),
817 branch: Some("fix-login".to_owned()),
818 }],
819 _ => vec![],
820 },
821 }),
822 }
823 }
824
825 fn agent(member_of: &[&str], scope: AgentScope) -> User {
826 User {
827 id: "usr_g1t_agent".to_owned(),
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent828 username: "g1t".to_owned(),
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API829 kind: PrincipalKind::Agent,
830 verified: true,
831 workspaces: member_of
832 .iter()
833 .map(|slug| Membership::member(*slug))
834 .collect(),
835 avatar: None,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look836 grants: Vec::new(),
Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step837 token: None,
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API838 acting: Some(Box::new(Acting {
839 credential_id: "tok_1".to_owned(),
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent840 agent: "g1t".to_owned(),
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API841 on_behalf_of: Principal {
842 id: "usr_1".to_owned(),
843 username: "syntaqx".to_owned(),
844 },
845 scope,
846 })),
847 }
848 }
849
850 fn op(kind: RunCredentialKind, usage: CredentialUse, operation: &str) -> Decision {
851 let scope = scope(kind, usage);
852 let user = agent(&["acme"], scope.clone());
853 decide_operation(
854 &user,
855 &scope,
856 operation,
857 Some(&path("acme", "rocket")),
858 true,
859 Some(7),
860 )
861 }
862
863 use CredentialUse::{Runner, Tools};
864 use RunCredentialKind as K;
865
866 /// Which operations each kind of run may use through its tools: the
867 /// allowed and denied matrix.
868 #[test]
869 fn tools_matrix() {
870 let cases: [(&str, [bool; 6]); 12] = [
871 // implement revise answer review plan checks
872 ("get_issue", [true, true, true, true, true, false]),
873 ("create_issue", [true, true, true, false, true, false]),
874 ("add_comment", [true, true, true, true, false, false]),
875 (
876 "review_pull_request",
877 [false, false, false, true, false, false],
878 ),
879 ("remember", [true, true, true, false, false, false]),
880 ("take_messages", [true, true, true, false, false, false]),
881 ("record_session", [false, false, false, false, false, false]),
882 (
883 "merge_pull_request",
884 [false, false, false, false, false, false],
885 ),
886 (
887 "update_repo_settings",
888 [false, false, false, false, false, false],
889 ),
890 ("create_webhook", [false, false, false, false, false, false]),
891 (
892 "set_actions_secret",
893 [false, false, false, false, false, false],
894 ),
895 ("assign_issue", [false, false, false, false, false, false]),
896 ];
897 let kinds = [
898 K::Implement,
899 K::Revise,
900 K::Answer,
901 K::Review,
902 K::Plan,
903 K::Checks,
904 ];
905 for (operation, expected) in cases {
906 for (kind, allowed) in kinds.into_iter().zip(expected) {
907 assert_eq!(
908 op(kind, Tools, operation).allowed,
909 allowed,
910 "{operation} by a {} run's tools",
911 kind.as_str()
912 );
913 }
914 }
915 }
916
917 #[test]
918 fn runner_matrix() {
919 assert!(op(K::Implement, Runner, "record_session").allowed);
920 assert!(op(K::Implement, Runner, "mark_pull_request_ready").allowed);
921 assert!(op(K::Revise, Runner, "record_session").allowed);
922 assert!(!op(K::Revise, Runner, "mark_pull_request_ready").allowed);
923 assert!(!op(K::Implement, Runner, "create_issue").allowed);
924 assert!(!op(K::Review, Runner, "record_session").allowed);
925 assert!(!op(K::Checks, Runner, "get_issue").allowed);
926 }
927
928 #[test]
929 fn settings_billing_tokens_and_members_are_never_reachable() {
930 for kind in RunCredentialKind::ALL {
931 for usage in [Runner, Tools] {
932 for operation in NEVER.iter().copied() {
933 let decision = op(kind, usage, operation);
934 assert!(!decision.allowed);
935 assert_eq!(decision.rule, "never");
936 }
937 }
938 }
939 // Even a scope that lists one is refused.
940 let mut wide = scope(K::Implement, Tools);
941 wide.operations.push("merge_pull_request".to_owned());
942 let user = agent(&["acme"], wide.clone());
943 let decision = decide_operation(
944 &user,
945 &wide,
946 "merge_pull_request",
947 Some(&path("acme", "rocket")),
948 true,
949 Some(7),
950 );
951 assert_eq!(decision.rule, "never");
952 }
953
954 #[test]
955 fn another_repository_is_refused() {
956 let scope = scope(K::Implement, Tools);
957 let user = agent(&["acme"], scope.clone());
958 let decision = decide_operation(
959 &user,
960 &scope,
961 "create_issue",
962 Some(&path("acme", "other")),
963 true,
964 None,
965 );
966 assert!(!decision.allowed);
967 assert_eq!(decision.rule, "scope:repository");
968 let decision = decide_operation(&user, &scope, "create_issue", None, true, None);
969 assert_eq!(decision.rule, "scope:repository");
970 // The repository's name is matched without regard to case.
971 let decision = decide_operation(
972 &user,
973 &scope,
974 "create_issue",
975 Some(&path("Acme", "Rocket")),
976 true,
977 None,
978 );
979 assert!(decision.allowed);
980 assert_eq!(decision.rule, "run:implement/tools");
981 }
982
983 #[test]
984 fn the_permission_is_the_intersection_with_the_person() {
985 let scope = scope(K::Implement, Tools);
986 // The person left the workspace: their agent can do nothing there.
987 let user = agent(&[], scope.clone());
988 let decision = decide_operation(
989 &user,
990 &scope,
991 "get_issue",
992 Some(&path("acme", "rocket")),
993 true,
994 Some(1),
995 );
996 assert!(!decision.allowed);
997 assert_eq!(decision.rule, "on-behalf-of:membership");
998 // And an owner's agent is only ever a member.
999 let owner = vec![
1000 Membership {
1001 slug: "acme".to_owned(),
1002 role: Role::Owner,
1003 name: None,
1004 avatar: None,
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1005 base_permission: Some(BasePermission::None),
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API1006 },
1007 Membership::member("elsewhere"),
1008 ];
1009 let memberships = intersect(&owner, "Acme");
1010 assert_eq!(memberships.len(), 1);
1011 assert_eq!(memberships[0].slug, "acme");
1012 assert_eq!(memberships[0].role, Role::Member);
1013 assert!(intersect(&owner, "nowhere").is_empty());
1014 }
1015
Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1016 /// An agent gets at most the person's role on the repository, and
1017 /// never more than Write; nothing outside the run's workspace.
1018 #[test]
1019 fn an_agent_has_at_most_its_persons_role() {
1020 use crate::access::{Capability, RepoRef, can, permission};
1021 let rocket = RepoRef { id: "rep_1", namespace: "acme", private: true };
1022 let other = RepoRef { id: "rep_2", namespace: "acme", private: true };
1023 let elsewhere = RepoRef { id: "rep_3", namespace: "globex", private: true };
1024 let tools = scope(K::Implement, Tools);
1025 let scope = scope(K::Implement, Runner);
1026 // An owner's agent: Write, never Admin.
1027 let owner = [Membership { role: Role::Owner, ..Membership::member("acme") }, Membership::member("globex")];
1028 let mut agent_user = agent(&[], scope.clone());
1029 agent_user.workspaces = intersect(&owner, "acme");
1030 assert_eq!(permission(Some(&agent_user), rocket), Some(RepoRole::Write));
1031 assert!(!can(Some(&agent_user), rocket, Capability::ManageSettings));
1032 assert_eq!(permission(Some(&agent_user), elsewhere), None);
1033 // A member whose workspace gives Read: Read, so it cannot push.
1034 let reader = [Membership { base_permission: Some(BasePermission::Read), ..Membership::member("acme") }];
1035 agent_user.workspaces = intersect(&reader, "acme");
1036 assert_eq!(permission(Some(&agent_user), rocket), Some(RepoRole::Read));
1037 assert!(!can(Some(&agent_user), rocket, Capability::Push));
1038 // An outside collaborator with Maintain on one repository: Write
1039 // there, nothing elsewhere, and the run is allowed.
1040 let grants = [
1041 RepoGrant { repo_id: "rep_1".into(), workspace: "acme".into(), role: RepoRole::Maintain },
1042 RepoGrant { repo_id: "rep_3".into(), workspace: "globex".into(), role: RepoRole::Admin },
1043 ];
1044 agent_user.workspaces = intersect(&[], "acme");
1045 agent_user.grants = intersect_grants(&grants, "Acme");
1046 assert_eq!(permission(Some(&agent_user), rocket), Some(RepoRole::Write));
1047 assert_eq!(permission(Some(&agent_user), other), None);
1048 assert_eq!(permission(Some(&agent_user), elsewhere), None);
1049 let decision = decide_operation(&agent_user, &tools, "get_issue", Some(&path("acme", "rocket")), true, Some(1));
1050 assert!(decision.allowed, "{}", decision.reason.unwrap_or_default());
1051 // The person, downstream of a runner's credential, carries the same.
1052 let person = as_person(&agent_user).expect("a runner acts as the person");
1053 assert_eq!(permission(Some(&person), rocket), Some(RepoRole::Write));
1054 }
1055
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API1056 #[test]
1057 fn a_runner_changes_only_its_own_pull_request() {
1058 let scope = scope(K::Implement, Runner);
1059 let user = agent(&["acme"], scope.clone());
1060 let repo = path("acme", "rocket");
1061 let other = decide_operation(&user, &scope, "record_session", Some(&repo), true, Some(8));
1062 assert!(!other.allowed);
1063 assert_eq!(other.rule, "scope:pull");
1064 let own = decide_operation(&user, &scope, "record_session", Some(&repo), true, Some(7));
1065 assert!(own.allowed);
1066 // Reading another is fine.
1067 assert!(
1068 decide_operation(
1069 &user,
1070 &scope,
1071 "get_pull_request",
1072 Some(&repo),
1073 true,
1074 Some(8)
1075 )
1076 .allowed
1077 );
1078 }
1079
1080 #[test]
1081 fn git_matrix() {
1082 let fork = path("pulls", "pul_7");
1083 let upstream = path("acme", "rocket");
1084 let elsewhere = path("acme", "billing");
1085 let implement = scope(K::Implement, Runner);
1086 assert!(decide_git(&implement, &fork, true).allowed);
1087 assert!(decide_git(&implement, &fork, false).allowed);
1088 assert!(decide_git(&implement, &upstream, false).allowed);
1089 assert_eq!(decide_git(&implement, &upstream, true).rule, "git:push");
1090 assert_eq!(decide_git(&implement, &elsewhere, false).rule, "git:read");
1091 let review = scope(K::Review, Runner);
1092 assert!(decide_git(&review, &upstream, false).allowed);
1093 assert!(!decide_git(&review, &upstream, true).allowed);
1094 assert!(!decide_git(&review, &fork, true).allowed);
1095 // A tools token made before run credentials never reaches git.
1096 let old = AgentScope {
1097 repo: upstream.clone(),
1098 operations: vec!["get_issue".to_owned()],
1099 run: None,
1100 };
1101 assert_eq!(decide_git(&old, &upstream, false).rule, "git:not-a-run");
1102 // Nor does an agent's tools token.
1103 assert_eq!(
1104 decide_git(&scope(K::Implement, Tools), &upstream, false).rule,
1105 "git:not-a-run"
1106 );
1107 }
1108
1109 #[test]
1110 fn a_push_moves_only_granted_branches() {
1111 let update = scope(K::Update, Runner);
1112 let repo = path("acme", "rocket");
1113 let refs = |names: &[&str]| {
1114 names
1115 .iter()
1116 .map(|name| (*name).to_owned())
1117 .collect::<Vec<_>>()
1118 };
1119 assert!(decide_refs(&update, &repo, &refs(&["refs/heads/fix-login"])).allowed);
1120 assert_eq!(
1121 decide_refs(&update, &repo, &refs(&["refs/heads/main"])).rule,
1122 "git:ref"
1123 );
1124 assert_eq!(
1125 decide_refs(
1126 &update,
1127 &repo,
1128 &refs(&["refs/heads/fix-login", "refs/tags/v1"])
1129 )
1130 .rule,
1131 "git:ref"
1132 );
1133 let implement = scope(K::Implement, Runner);
1134 assert!(
1135 decide_refs(
1136 &implement,
1137 &path("pulls", "pul_7"),
1138 &refs(&["refs/heads/main"])
1139 )
1140 .allowed
1141 );
1142 }
1143
1144 #[test]
1145 fn a_runner_acts_downstream_as_the_person() {
1146 let user = agent(&["acme"], scope(K::Implement, Runner));
1147 let person = as_person(&user).unwrap();
1148 assert_eq!(person.id, "usr_1");
1149 assert_eq!(person.username, "syntaqx");
1150 assert_eq!(person.kind, PrincipalKind::User);
1151 assert!(person.is_member("acme"));
1152 assert!(person.acting.is_none());
g1t is one name: its agent's work, commits and comments show as @g1t, and nobody can claim g1t or g1t-agent1153 assert_eq!(describe(&user), "g1t on behalf of syntaqx");
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API1154 // The tools act as the agent.
1155 assert!(as_person(&agent(&["acme"], scope(K::Implement, Tools))).is_none());
1156 }
1157
1158 #[test]
1159 fn scopes_without_a_run_still_parse() {
1160 let old: AgentScope = serde_json::from_str(
1161 r#"{"repo":{"namespace":"acme","name":"rocket"},"operations":["get_issue"]}"#,
1162 )
1163 .unwrap();
1164 assert!(old.run.is_none());
1165 let written = serde_json::to_string(&scope(K::Review, Tools)).unwrap();
1166 assert!(written.contains(r#""use":"tools""#));
1167 assert!(written.contains(r#""kind":"review""#));
1168 let back: AgentScope = serde_json::from_str(&written).unwrap();
1169 assert_eq!(back.run.unwrap().kind, K::Review);
Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily1170 // Only g1t's own runs say so; every other reads as not.
1171 assert!(!written.contains("system"));
1172 assert!(!back_run(&written).system);
1173 let mut own = scope(K::Bump, Runner);
1174 own.run.as_mut().unwrap().system = true;
1175 let written = serde_json::to_string(&own).unwrap();
1176 assert!(written.contains(r#""system":true"#));
1177 assert!(back_run(&written).system);
1178 }
1179
1180 fn back_run(written: &str) -> RunBinding {
1181 serde_json::from_str::<AgentScope>(written).unwrap().run.unwrap()
Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API1182 }
1183}