Context assistance and CIGAR integration
Context assistance is an optional Guard service that gives approved agents and apps small, source-linked pieces of local context. Guard remains the authority for consent, private evidence, runtime trust, workspace access, and recovery while CIGAR prepares and answers context requests in a separate managed process.
System boundary
The subsystem joins four roles without giving any one role full control:
| Role | Responsibility |
|---|---|
| Native Guard runtime | Owns settings, consent, source admission, policy facts, runtime verification, and lifecycle state. |
| CIGAR runtime | Builds scoped graphs and returns context briefs with citations. |
| Integrations | Carry bounded requests between Guard-owned capabilities and the CIGAR SDK. |
| Dashboard and CLI | Let an operator inspect status, choose sources, manage runtimes, and recover failed jobs. |
The CIGAR process is optional. When it is off or unavailable, Guard keeps its normal protection and approval behavior. A saved preference does not prove that a verified runtime is active.
The following diagram shows how a context request moves through the trust boundary and returns as an explainable result.
flowchart LR
A[Agent or AI app] --> B[Dashboard, CLI, or integration]
B --> C[Native Guard service]
C --> D[Consent and scope checks]
D --> E[Admitted private evidence]
C --> F[Verified managed runtime]
E --> F
F --> G[CIGAR graph or broker]
G --> H[Scoped brief with citations]
H --> C
C --> B
Native authority
The native service is the control point for context assistance. It keeps activation separate from settings, checks the selected runtime before use, and revokes context authority when the runtime stops or changes. Its public adapters only frame requests and responses; they do not decide whether CIGAR is available.
References: rust/…/lib.rs• L1-4 rust/…/context_assistance_service.rs• L1-7 rust/…/context_assistance_engine.rs• L180-243 src/…/native_context_assistance.py• L1-36
CIGAR process boundary
CIGAR runs behind a private line-based bridge. Guard starts it only after it verifies the package, interpreter, platform, and release contract. The bridge exposes graph and broker operations, but it does not read host files or receive Guard credentials.
References: rust/…/runtime.rs• L138-165 rust/…/runtime.rs• L203-275 integrations/…/bridge.py• L1-5 integrations/…/bridge.py• L154-189
Context and evidence model
Context assistance treats local material as evidence with a known source and scope. Guard admits the material first, removes unsafe or private content, and then gives CIGAR only the documents that a workspace or broker capability permits.
Private evidence
Private evidence includes native policy facts, sanitized receipt facts, and selected workspace documents. A source root must be explicitly admitted, and each requested file is checked again before and after reading. Secret matches, unsafe paths, stale roots, and malformed text stop the transfer instead of producing partial context.
References: rust/…/config.rs• L52-70 rust/…/source.rs• L1-7 rust/…/source.rs• L66-107
Scoped context
A workspace is a bounded context area that combines admitted sources with a policy revision. A view is the narrower set of sources exposed to one consumer. CIGAR returns a brief and citations from that view, while Guard retains the full context needed to check currentness and scope.
References: rust/…/graph.rs• L13-35 rust/…/graph.rs• L40-70 rust/…/graph.rs• L113-169 rust/…/graph.rs• L249-276
Prompt context assistance
Prompt context assistance connects an approved AI-app prompt to the smallest useful parts of its project. It identifies named files, code names, quoted text, tests, documentation, and change requests. It then gives CIGAR a screened set of candidate files or builds a compact map of definitions, uses, related tests, docs, and imports for the agent to open.
The path from a prompt to added context stays bounded and does not make the prompt an authority request:
flowchart LR
A[Allowed prompt] --> B[Project and prompt match]
B --> C[Screened candidate files]
C --> D[CIGAR map or brief]
C --> E[Guard fallback excerpts]
D --> F[Additional prompt context]
E --> F
Only an allowed prompt from a supported harness can receive this context. Guard does not walk links or trusted project commands during matching. It rechecks each file through the source screen before sending it to CIGAR or placing its text in the prompt. If CIGAR is still starting or busy, Guard can return screened excerpts or matching file names instead.
Change prompts use a separate review path. Guard can describe changes since the session began or show the newest commit for a teammate change or failure. For failure prompts, the newest-commit note also points the agent to changed definitions and can provide one bounded test command when the prompt names a small set of safe tests inside the project. It uses only trusted offline Git activity, screens changed files and diff text, and leaves out data that it cannot read safely.
The context is session-aware. A harness can receive a range or excerpt once and refer to it again without carrying the same code on every prompt. Edited text is treated as new context. Guard also gives Claude Code and Codex a one-time hint to use the supplied context efficiently.
References: rust/…/context_assistance_prompt.rs• L1-16 rust/…/context_assistance_prompt.rs• L140-284 rust/…/context_assistance_prompt_files.rs• L70-97 rust/…/context_assistance_prompt_files.rs• L149-171 rust/…/context_assistance_prompt_map.rs• L161-193 rust/…/context_assistance_prompt_changes.rs• L94-127 rust/…/context_assistance_prompt_changes_fix.rs• L14-43 rust/…/context_assistance_prompt_changes_fix.rs• L46-86 rust/…/context_assistance_prompt_seen.rs• L17-25
Brokered sharing
The broker coordinates context between clients that Guard has authenticated and bounded. It tracks source revisions, proposals, leases, provenance, and execution handoffs so that a context result cannot become authority by itself. Broker handles are native capabilities, not caller-supplied IDs or credentials.
See broker and workspace workflows for the request, review, lease, and workspace flows.
References: rust/…/broker.rs• L1-9 rust/…/broker.rs• L39-77 rust/…/broker.rs• L89-124 integrations/…/broker_client.py• L1-4
Managed runtime lifecycle
Guard manages the Python environment as a private, approved runtime rather than using the user's Python installation. The lifecycle separates selection, verification, activation, use, stopping, and cleanup so a failed or changed environment cannot silently regain access.
Runtime qualification
An enrolled runtime is usable only when its interpreter, package tree, native worker, platform, and release metadata match an approved release. Guard repeats the checks before activation and during the handshake. This produces a verified runtime capability; it does not grant source access or permission to perform Guard actions.
References: rust/…/artifacts.rs• L17-52 rust/…/artifacts.rs• L87-111 rust/…/artifacts.rs• L202-254 rust/…/runtime.rs• L203-265
Runtime activity
The native service owns one optional runtime lane and keeps its work outside synchronous Guard decisions. Requests use a bounded queue and a deadline. A pause or shutdown closes admission before a lifecycle change, then cleans up the old process and its retained state.
References: rust/…/actor.rs• L1-16 rust/…/actor.rs• L44-63 rust/…/actor.rs• L108-151 rust/…/actor.rs• L185-215 rust/…/context_assistance_service.rs• L123-138
Managed Python environment
The Python interpreter and its package files come from native-owned installation records. Guard verifies the binding and bytes for each process owner. The integration starts Python in an isolated mode that excludes user-site and path injection, so the existing user environment is not changed or trusted.
References: rust/…/private_python.rs• L11-24 rust/…/private_python.rs• L26-72 integrations/…/bridge.py• L8-16 integrations/…/broker_client.py• L6-14
Catalog and artifact operations
The catalog describes which CIGAR builds and private interpreters Guard may prepare for a host. Installation and update work use that catalog as a signed, exact input; they do not resolve arbitrary packages or let a browser choose executable paths.
Catalog selection
Guard can inspect bundled or trusted imported catalog data without starting CIGAR. A catalog can list builds, interpreter choices, platform support, features, withdrawal state, and freshness. Imported data does not enable CIGAR, select a runtime, grant source access, or replace an installed approval.
References: rust/…/context_assistance_catalog.rs• L1-5 rust/…/context_assistance_catalog.rs• L59-113 rust/…/context_assistance_catalog.rs• L115-140 integrations/…/release-catalog.v1.json• L1-20
Artifact installation
Installation acquires only the wheels and dependencies named by the approved release. Guard checks origin policy, size, and digest before publishing each artifact to its managed cache. It then builds an installation record that later runtime verification can authenticate.
References: rust/…/context_assistance_acquisition.rs• L1-6 rust/…/context_assistance_acquisition.rs• L70-129 rust/…/context_assistance_acquisition.rs• L158-193
Update and switch
An update prepares and checks a target beside the current runtime while the current selection remains in use. A separate, explicit commit changes the selection. A live switch pauses the old runtime and invalidates its context authority, so applications and source access must reconnect under the new generation. If CIGAR is off, selection can commit while keeping it off.
The dashboard keeps preparation, selection, switching, rollback, and reconnect as separate choices. A prepared live switch waits for the operator to confirm that sources and app connections can be granted again; Guard approvals remain in place.
See CIGAR artifact installation and release for the catalog, artifact, release, and switch lifecycle.
References: rust/…/context_assistance_service_upgrade.rs• L1-5 rust/…/context_assistance_service_upgrade.rs• L171-208 dashboard/…/versions-builds-panel.tsx• L46-65 dashboard/…/versions-jobs-panel.tsx• L42-67 dashboard/…/versions-tutorial.ts• L13-35
Recovery and rollback
Update jobs persist progress so Guard can report cleanup, cancellation, recovery, or rollback needs. Progress records are not runtime capabilities. Recovery must reconcile the job with the current native state, and it never restores an old actor, source grant, or app connection from disk alone.
References: rust/…/context_assistance_service_upgrade.rs• L44-72 rust/…/context_assistance_service_upgrade.rs• L144-176 src/…/context_assistance_versions_commands.py• L43-47 src/…/context_assistance_versions_commands.py• L129-145 dashboard/…/versions-jobs-panel.tsx• L60-78
Operator surfaces
The dashboard, HTTP service, CLI, and integration entry points present one native state model. They expose status and jobs for inspection, require the appropriate Guard approval for access expansion or lifecycle changes, and return stable error codes without exposing local paths or source text.
Dashboard workspace
The CIGAR workspace gives operators one place to understand the feature and manage its main lifecycle. Home explains prompt matching, Projects selects folders and files, Settings controls runtime and context choices, Updates handles release preparation, Usage shows counts from local AI-app records, Privacy shows retained data and repair actions, and Guide provides walkthroughs. CIGAR is off until enabled, and the dashboard treats a saved preference as separate from a ready runtime.
The normal access path is deliberately narrow. The operator chooses a project folder, selects the files CIGAR may read, and grants that scope through Guard. The built-in prompt integrations use the selected project scope automatically; other protected apps connect with a short-lived code and receive only the chosen project access. Context can add information to an agent request, but it does not approve commands.
The dashboard also makes data and state boundaries visible. Memory-only notes disappear when CIGAR stops, while saved notes can be removed separately. Removing all CIGAR data ends project access and app connections; browser project shortcuts are only a convenience and must be confirmed again after a restart.
References: dashboard/…/workspace-model.ts• L3-12 dashboard/…/workspace-sections.tsx• L32-87 dashboard/…/workspace-story.tsx• L24-57 dashboard/…/workspaces-panel.tsx• L109-188 dashboard/…/usage-panel.tsx• L64-101 dashboard/…/data-repair-panel.tsx• L26-35 dashboard/…/data-repair-panel.tsx• L96-121
One-click setup
Turning CIGAR on is an explicit dashboard action. The page first reads native metadata, then follows the shortest safe path: reuse an approved runtime, prepare private Python when needed, download and check a build, commit a selection, save the preference, and wait for Guard to report a live ready state. It does not invent a build or retry an operation whose result is unknown.
If the operator leaves during setup, the browser remembers the unfinished request for that tab for a short window. When the operator returns, the page can finish a held safety check or continue from completed preparation steps. Stopping cancels the active job and prevents later setup stages; a setup that reaches the start stage turns CIGAR off when the operator stops it.
References: dashboard/…/one-click.ts• L38-88 dashboard/…/one-click.ts• L201-248 dashboard/…/one-click.ts• L251-333 dashboard/…/setup-resume.ts• L4-13 dashboard/…/setup-resume.ts• L49-57 dashboard/…/use-one-click.ts• L114-129 dashboard/…/use-one-click.ts• L239-247
Project and source selection
Project selection is the dashboard's source boundary for local files. The folder picker browses bounded, real folders without opening files, while the file picker offers only readable project files and marks files that cannot be used. Both surfaces apply the same path and credential rules as a source grant, but a listing grants nothing; the grant re-validates every path on its own. A project can be added without selecting documents when the operator wants Guard's safety facts but no file content.
The Projects view can show a preview of the context that an AI app would receive, with excerpts and source citations. The preview is a point-in-time result; after files or project choices change, the operator must read the files again or compile a new brief.
Operator-picked project folders are the only workspace grants that return after a restart, and they return by being picked again by path. Saved evidence does not restore a grant. Agent-facing consumers must bind to a native caller with an existing app grant, so retained data alone cannot reopen project access.
References: dashboard/…/folder-picker.tsx• L18-23 dashboard/…/folder-picker.tsx• L104-112 dashboard/…/project-files-picker.tsx• L6-16 dashboard/…/project-files-picker.tsx• L75-99 dashboard/…/folders-api.ts• L54-75 dashboard/…/workspaces-panel.tsx• L122-180 rust/…/context_assistance_engine.rs• L1-4 rust/…/context_assistance_engine.rs• L228-243 rust/…/context_assistance_engine.rs• L328-371 rust/…/context_assistance_folders.rs• L1-5 rust/…/context_assistance_folders.rs• L257-290 rust/…/context_assistance_folders.rs• L397-438
Agent connections
Agent connections extend one approved project scope to apps that do not receive matching files automatically. The operator checks the short-lived session code, names the app and project, and can choose whether the app may read approved shared notes or suggest new notes for review. A connection grants context access only; Guard keeps command approval separate.
See agent and tool integrations for the wider integration boundary.
References: dashboard/…/agents-panel.tsx• L15-18 dashboard/…/agents-panel.tsx• L79-100 dashboard/…/agents-panel.tsx• L113-159 dashboard/…/allow-files.tsx• L6-20
Usage accounting
The Usage view reports what each supported AI app recorded on the computer. It groups counts by app for today and a recent time window, with recent sessions for detail. The totals cover input, cached input, cache writes, output, requests, and chat summaries; they count whether CIGAR is on or off, and unsupported app records are named rather than estimated.
The first read can take time because Guard scans the recent session records. The dashboard shows counting or unavailable states instead of presenting incomplete totals as final data.
References: dashboard/…/usage-api.ts• L4-23 dashboard/…/usage-api.ts• L40-56 dashboard/…/usage-panel.tsx• L41-60 dashboard/…/usage-panel.tsx• L64-101
Privacy and repair
Privacy controls show counts for active scopes, selected files, prepared answers, history, and connected apps without showing source text. The operator can clear past answers, remove saved notes, delete all CIGAR data, turn CIGAR off, or start a fresh runtime. These actions remove context state but do not remove Guard approvals or Guard records.
References: dashboard/…/data-repair-panel.tsx• L26-35 dashboard/…/data-repair-panel.tsx• L39-57 dashboard/…/data-repair-panel.tsx• L152-197
Codex session setting
The workspace exposes a separate Codex session setting for long conversations. It can remove a summary size that Guard wrote to the Codex configuration, but it does not set a new size and leaves a limit set by the user unchanged. The setting works independently of CIGAR context matching.
References: dashboard/…/codex-lean-api.ts• L5-8 dashboard/…/codex-lean-api.ts• L40-49 dashboard/…/codex-lean.tsx• L22-27 dashboard/…/codex-lean.tsx• L61-81
HTTP and CLI interfaces
HTTP routes and CLI commands are presentation layers over the native service. Read operations expose status, installations, catalog data, interpreters, and jobs. Write operations cover activation, stopping, source access, catalog changes, installation, switching, cancellation, and recovery. High-risk changes pass through Guard approval gates.
References: src/…/context_assistance_http.py• L12-24 src/…/context_assistance_http.py• L65-83 src/…/context_assistance_versions_http.py• L10-15 src/…/context_assistance_commands.py• L13-32 src/…/context_assistance_versions_commands.py• L12-47
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the native status schema, HTTP validation, CLI output, and dashboard types aligned when a status field or error code changes.
- Keep release catalog identity, platform bindings, worker protocol, broker protocol, and artifact digests aligned with runtime approval checks.
- Preserve the rule that runtime selection, activation, source grants, and app connections are separate state changes.
- When a generation or switch boundary changes, invalidate old context handles and require fresh source and app admission.
- Keep bridge operations bounded and credential-free when adding a CIGAR SDK capability.
- Keep catalog imports and update progress unable to enable a runtime or restore a capability by themselves.
- Keep folder and file selection, source grants, app connection scopes, and dashboard descriptions aligned when the project access contract changes.
- Keep prompt matching, project-root rules, file screening, CIGAR lookup, and Guard fallback behavior aligned when prompt context changes.
- Keep change-review context restricted to trusted offline Git output and screened current file text. Do not let a partial walk claim that a rename or diff is complete.
- Keep failure-prompt guidance limited to the newest change and safe, bounded test commands derived from in-project paths.
- Keep session span tracking aligned with harness behavior so repeated context is not sent when the harness retains it, and is sent again when the source text changes.
- Keep privacy actions consistent across retained CIGAR data, project access, app sessions, and browser-only recent project shortcuts.
- Keep the Codex setting contract separate from CIGAR context settings so a user-owned Codex limit is never overwritten.
- Keep one-click setup resume records, native job identity, generation checks, approval use, and cancellation behavior aligned so a lost reply is observed rather than submitted twice.
- Keep usage labels and totals aligned with the local records that Guard can read; do not imply that missing app records are estimates.
- Keep the dashboard's preparation, explicit switch, reconnect acknowledgement, rollback, and recovery states aligned with native job phases.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Package, worker, interpreter, or release digest differs from the approved record | Runtime activation is refused | Recheck protected bytes before the interpreter probe and after the bridge handshake |
| A source root changes identity or a file contains a secret match | Context admission fails and no partial text is sent | Revalidate the root and scan the complete file before transfer |
| A live switch or stop begins while context work is active | Old handles and app access become invalid | Pause admission, revoke the old generation, and require fresh grants |
| A catalog is expired, untrusted, or marks a build withdrawn | New preparation cannot use that build | Require current catalog trust and keep installed receipts separate from new preparation |
| A lifecycle job is cancelled or its outcome is unknown | The service may remain busy or require explicit recovery | Retain cleanup ownership and reconcile the job before another switch |
| CIGAR is unavailable or disabled | Context assistance stops, but Guard protection continues | Keep the optional service outside the resident policy health circuit |
| A prompt has no approved project scope or its harness does not pass added context to the model | No project context is added | Require an allowed prompt, selected project context, and a supported harness contract |
| CIGAR is starting, busy, or late during a prompt hook | Guard returns only safe local excerpts or matching file names, or adds nothing if no safe match fits | Keep the fallback bounded and run the same source screen before adding text |
| The project walk is incomplete or a changed file fails the read screen | The map cannot claim that all uses or changes were found | Mark the result as partial or omit the unsafe file instead of presenting a complete rename or diff |
| A prompt asks about a changed project and Git cannot be trusted or runs out of time | Change context is omitted or reduced to safe file matches | Use trusted offline Git only and keep the hook deadline authoritative |
| A failure prompt names unsafe, outside, or too many test paths | The context lead does not provide a test command | Accept only simple test paths that resolve inside the project and keep the command bounded |
| A project file or folder changes after it was selected | A brief or grant becomes stale and cannot claim current source content | Re-read the files or add the project again before compiling context |
| An app connection expires, is revoked, or exceeds capacity | The app cannot request the project context | Use a fresh connection code and choose an active project scope again |
| Saved notes need repair or all data is deleted | Retained context is unavailable and projects or app connections must be added again | Use Privacy repair actions, then establish fresh access under the current runtime |
| The Codex config is unreadable or has a user-owned limit | The lean-session setting does not change | Fix the Codex config or leave the user-owned value in place |
| A setup reply is lost after Guard may have accepted the job | Repeating the action can duplicate work or cross a stale boundary | Follow the job or live status by ID before allowing another submit |
| A prepared switch no longer matches the live generation or selection | The switch is refused and context remains on the current boundary | Refresh native status and jobs, then prepare a new selection |
| Usage records are unavailable or still being counted | The dashboard cannot show complete totals | Show counting or unavailable state and do not treat partial data as final |
Key files
| File | Why to read it |
|---|---|
| rust/…/context_assistance_service.rs | Shows the native owner for activation, verification, runtime state, and shutdown. |
| rust/…/context_assistance_engine.rs | Shows workspace grant ownership, context retention, source refresh, agent binding, and clearing rules. |
| rust/…/runtime.rs | Defines the verified runtime boundary and release checks. |
| rust/…/source.rs | Shows how private workspace evidence becomes admitted context. |
| rust/…/graph.rs | Explains workspaces, views, revisions, and cited briefs. |
| rust/…/broker.rs | Defines broker domains, clients, proposals, provenance, and execution handoffs. |
| rust/…/context_assistance_prompt.rs | Coordinates prompt matching, CIGAR lookup, safe fallback context, and harness output. |
| rust/…/context_assistance_prompt_files.rs | Explains project discovery and bounded candidate selection before source screening. |
| rust/…/context_assistance_prompt_map.rs | Shows how a prompt becomes a compact map of definitions, uses, tests, docs, and related code. |
| rust/…/context_assistance_prompt_changes.rs | Shows how change prompts receive screened session or commit context. |
| rust/…/context_assistance_prompt_changes_fix.rs | Shows how failure prompts receive focused newest-change guidance and bounded test instructions. |
| rust/…/context_assistance_prompt_seen.rs | Defines session-aware reuse of context already shown to an agent. |
| rust/…/context_assistance_folders.rs | Defines the safe folder and file browsing boundary used by project selection. |
| rust/…/context_assistance_catalog.rs | Describes catalog trust, freshness, withdrawal, and release selection. |
| rust/…/context_assistance_acquisition.rs | Shows the exact artifact acquisition boundary. |
| rust/…/context_assistance_service_upgrade.rs | Shows prepare, switch, cancellation, cleanup, and recovery ownership. |
| integrations/…/bridge.py | Shows the private SDK bridge for graph and broker operations. |
| src/…/context_assistance_http.py | Maps native context state to dashboard HTTP routes and approval gates. |
| dashboard/…/workspace.tsx | Shows the top-level operator flow and lifecycle sections. |
| dashboard/…/workspace-model.ts | Shows the dashboard state model, section order, and readiness rules. |
| dashboard/…/workspaces-panel.tsx | Shows project grants, source refresh, context previews, and app handoff. |
| dashboard/…/agents-panel.tsx | Shows how protected apps connect to an approved project scope. |
| dashboard/…/one-click.ts | Shows the safe setup plan, job follow-up, approval boundary, and live readiness check. |
| dashboard/…/setup-resume.ts | Shows how an unfinished setup click can resume without restoring authority from browser state. |
| dashboard/…/versions-builds-panel.tsx | Shows artifact preparation, Python choices, and explicit runtime selection. |
| dashboard/…/versions-jobs-panel.tsx | Shows switch confirmation, reconnect boundaries, cancellation, and cleanup. |
| dashboard/…/data-repair-panel.tsx | Shows retained-data counts, deletion boundaries, and repair actions. |
| dashboard/…/usage-panel.tsx | Shows how local AI-app usage records become operator-facing totals. |