Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,42 @@ Changes are recorded here before a release version is assigned.

### Added

- Version 0.95.0 lets a workspace give its `gh` profile a GitHub review host's
token (ADR-0147). `omgcode workspace gh-token-bind <workspace> <profile>
<host>`, `gh-token-unbind`, and `gh-token-list`, or the **GitHub token**
select beside each assigned profile on a workspace's page of the `settings`
window (a native confirmation binds; unbinding needs none), bind a profile
to a review host of kind `github`. A model command whose program is that
profile's `gh` then gets the token as `GH_TOKEN` and network access. The
workspace's `task_network` preference must permit it, and the call runs
without an approval only when the command state and `task_network` are both
`allow`; the approval shows **Network** on and the host's name, and the
digest includes the host. Commands are limited to `pr`, `issue`, `repo`,
`api`, `run`, `workflow`, `release`, `search`, `label`, and `status`
(without `repo clone` and `pr checkout`, and with the subcommand directly
after the command); a URL, `--hostname`, a `ghe.com`
or `github.localhost` name, a repository qualified by any host other than
`github.com` (a `--repo` value such as `intranet/owner/repo` too), the
Git-starting flags `--clone`, `--remote`, and `--checkout`, `--web` or
`-w`, a jq filter (`--jq` or `-q`), which could read the token from the
environment, and editor mode (`--editor`, or `-e`
where it means that) are refused before an
approval (`gh_arguments_refused`), as is a call while `task_network` is off
(`github_network_disabled`). The run gets an empty, read-only `gh`
configuration folder, the profile cannot override the `GH_*` variables or
proxies, a profile whose `PATH` holds `git` is refused, the token's bytes
are replaced in the output (with any trailing prefix when it was
truncated), the run journal records the host's name and identifier only,
and the run stops when the binding ends or names another host, even one
added again under the same name; the runner also refuses a run whose bound
host identifier changed after the turn admitted it. Each binding keeps room
for its unbind in the settings journal. A file argument such as
`--body-file` can name any file the run can read; Linux Landlock grants no
`/proc`, so `/proc/self/environ` stays out of reach, which a new
confinement probe checks directly and through a link. GitHub Enterprise
hosts are refused. The security rules record this as the one credential allowed in a
task environment. **No `gh` run with a token was made against GitHub**, and
`gh` has passed no confined acceptance run.
- Version 0.93.0 implements increment 4b of the pull request review contract,
the GitLab, Azure DevOps, and Bitbucket fetch adapters (ADR-0145). Every host
kind now has an adapter. **No adapter has run against a real host**: each was
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/omgcode-core", "crates/omgcode-cli", "crates/omgcode-platform", "crates/omgcode-app", "crates/omgcode-desktop"]

[workspace.package]
version = "0.93.0"
version = "0.95.0"
edition = "2024"
rust-version = "1.99.1"
license = "Apache-2.0"
Expand Down
30 changes: 15 additions & 15 deletions crates/omgcode-app/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ pub use self::settings_discovery::{
};
pub use self::settings_execution::{
ContainerAccessChoice, ContainerGrantRequest, ContainerRevokeRequest, EnvironmentEntry,
GitWorkerGrantRequest, PackageProfileAddRequest, ProfileAssignmentRequest,
ProfileRemoveRequest, ToolchainProfileAddRequest,
GhTokenBindRequest, GhTokenUnbindRequest, GitWorkerGrantRequest, PackageProfileAddRequest,
ProfileAssignmentRequest, ProfileRemoveRequest, ToolchainProfileAddRequest,
};
pub use self::settings_folders::{FolderAddRequest, FolderRemoveRequest, FolderSetRequest};
pub use self::settings_skills::{SkillChoice, SkillRemoveRequest, SkillStateRequest};
Expand Down Expand Up @@ -184,19 +184,19 @@ pub use self::wire::{
ConnectionOrigin, ConnectionRemoveRequest, ConnectionSelectRequest, ConnectionSourceView,
ConnectionStatus, ConnectionStatusRequest, ConnectionView, ContainerGrantView,
ContextBreakdown, ContextMeterDto, ContextPartDto, ContextPartId, Decision, EntryKind,
GitIdentityRequest, GitIdentityView, GitIndexState, GitPathView, GitStatusState, GitStatusView,
GitWorkerState, GitWorkerView, GitWorktreeState, GrantedFolderView, MessageRoleDto,
ModelChoice, NewConnectionKind, PackageProfileView, PermissionFlags, PermissionsChangeRequest,
PreferencesSource, ProviderProfileView, ReviewHostAddRequest, ReviewHostRemoveRequest,
ReviewHostTokenRequest, ReviewHostView, ReviewInfoView, ReviewMark, ReviewOperation,
ReviewOperationError, ReviewOperationRequest, ReviewOperationState, ReviewProgressView,
ReviewRemoveResult, ReviewSkillList, ReviewSkillView, ReviewStartRequest, SearchHit,
SearchRequest, SearchResult, SearchRoleDto, SessionContext, SessionCreateRequest,
SessionEffortSelectRequest, SessionModelSelectRequest, SessionRequest, SessionSetup,
SessionSetupChoice, SessionSetupProvider, SessionSkills, SessionStatus, SessionSummary,
SessionTree, SettingsOverview, SettingsRevisionRequest, SettingsScope, SkillOverrideView,
SkillSettingView, SnippetPart, ToolOutcomeDto, ToolchainProfileView, ToolsMode,
TranscriptEntry, TranscriptPage, TranscriptRequest, TreeRequest, TreeSort, TreeView,
GhTokenBindingView, GitIdentityRequest, GitIdentityView, GitIndexState, GitPathView,
GitStatusState, GitStatusView, GitWorkerState, GitWorkerView, GitWorktreeState,
GrantedFolderView, MessageRoleDto, ModelChoice, NewConnectionKind, PackageProfileView,
PermissionFlags, PermissionsChangeRequest, PreferencesSource, ProviderProfileView,
ReviewHostAddRequest, ReviewHostRemoveRequest, ReviewHostTokenRequest, ReviewHostView,
ReviewInfoView, ReviewMark, ReviewOperation, ReviewOperationError, ReviewOperationRequest,
ReviewOperationState, ReviewProgressView, ReviewRemoveResult, ReviewSkillList, ReviewSkillView,
ReviewStartRequest, SearchHit, SearchRequest, SearchResult, SearchRoleDto, SessionContext,
SessionCreateRequest, SessionEffortSelectRequest, SessionModelSelectRequest, SessionRequest,
SessionSetup, SessionSetupChoice, SessionSetupProvider, SessionSkills, SessionStatus,
SessionSummary, SessionTree, SettingsOverview, SettingsRevisionRequest, SettingsScope,
SkillOverrideView, SkillSettingView, SnippetPart, ToolOutcomeDto, ToolchainProfileView,
ToolsMode, TranscriptEntry, TranscriptPage, TranscriptRequest, TreeRequest, TreeSort, TreeView,
WorkspaceChoice, WorkspaceGroup, WorkspaceInstructionsRequest, WorkspaceList,
WorkspaceRevisionRequest, WorkspaceSettingsView,
};
Expand Down
30 changes: 28 additions & 2 deletions crates/omgcode-app/src/desktop/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ use super::state::folder_of_directory;
use super::wire::{
BranchState, BranchView, ClaudeCodeGrantView, ClaudeCodeView, ConnectionChoice,
ConnectionOrigin, ConnectionSourceView, ConnectionStatus, ConnectionStatusRequest,
ConnectionView, ContainerGrantView, GitIdentityView, GitIndexState, GitPathView,
GitStatusState, GitStatusView, GitWorkerState, GitWorkerView, GitWorktreeState,
ConnectionView, ContainerGrantView, GhTokenBindingView, GitIdentityView, GitIndexState,
GitPathView, GitStatusState, GitStatusView, GitWorkerState, GitWorkerView, GitWorktreeState,
GrantedFolderView, PackageProfileView, ProviderProfileView, ReviewHostView, SessionContext,
SessionRequest, SessionSkills, SettingsOverview, SkillOverrideView, SkillSettingView,
ToolchainProfileView, WorkspaceSettingsView,
Expand Down Expand Up @@ -95,6 +95,31 @@ fn git_worker_view(store: &ControlStore, workspace: WorkspaceId, inner: &Inner)
}
}

/// The workspace's GitHub token bindings by profile and host name
/// (ADR-0147). A binding whose profile or host is no longer recorded is
/// left out; core ends such a binding itself.
fn gh_token_binding_views(
store: &ControlStore,
workspace_id: omgcode_core::policy::WorkspaceId,
) -> Vec<GhTokenBindingView> {
store
.gh_token_bindings()
.iter()
.filter(|binding| binding.workspace_id() == workspace_id)
.filter_map(|binding| {
let profile = store
.profiles()
.iter()
.find(|status| status.profile().id() == binding.profile_id())?;
let host = store.gh_token_host(workspace_id, binding.profile_id())?;
Some(GhTokenBindingView {
profile: profile.profile().name().to_owned(),
host: display_safe_line(host.name()),
})
})
.collect()
}

/// The recorded review hosts for display (ADR-0143). Whether a token is
/// readable is decided by core's checked load, which reads it and drops it at
/// once: nothing of it is kept, shown, or sent to the window. A native store
Expand Down Expand Up @@ -187,6 +212,7 @@ pub(super) fn overview_of(inner: &Inner, store: ControlStore) -> SettingsOvervie
.map(|status| status.profile().name().to_owned())
})
.collect(),
gh_token_bindings: gh_token_binding_views(&store, workspace.id()),
package_cache_root: store.package_cache_root_display(workspace.id()),
instructions: workspace_instructions_view(
&inner.data_root,
Expand Down
2 changes: 1 addition & 1 deletion crates/omgcode-app/src/desktop/settings_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ impl DesktopService {

/// As [`apply_checked`](Self::apply_checked) for a change that fails only
/// with a core settings error.
fn apply(
pub(super) fn apply(
&self,
change: impl FnOnce(&mut ControlStore) -> Result<(), ControlError>,
) -> Result<SettingsOverview, DesktopError> {
Expand Down
122 changes: 122 additions & 0 deletions crates/omgcode-app/src/desktop/settings_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,33 @@ pub struct ProfileAssignmentRequest {
pub name: String,
}

/// Arguments of `settings_bind_gh_token` (ADR-0147). Names only: the token
/// stays in protected storage and is read by the runner.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct GhTokenBindRequest {
/// The settings revision the window last read.
pub revision: u64,
/// A registered workspace.
pub workspace_id: Uuid,
/// The recorded name of a toolchain profile assigned to the workspace.
pub profile: String,
/// The recorded name of a review host of kind `github`.
pub host: String,
}

/// Arguments of `settings_unbind_gh_token` (ADR-0147).
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct GhTokenUnbindRequest {
/// The settings revision the window last read.
pub revision: u64,
/// A registered workspace.
pub workspace_id: Uuid,
/// The recorded name of the toolchain profile whose binding ends.
pub profile: String,
}

/// Arguments of `settings_add_package_profile`.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -483,6 +510,19 @@ fn unassign_confirmation(workspace_folder: &str, name: &str, revoked: &[String])
}
}

/// The native confirmation for giving a workspace profile's `gh` a review
/// host's token (ADR-0147). Fixed text apart from the three names.
fn bind_gh_token_confirmation(workspace_folder: &str, profile: &str, host: &str) -> Confirmation {
Confirmation {
title: "Give gh a GitHub token",
message: format!(
"Give the toolchain profile {} the token of the review host {} in the workspace\n{workspace_folder}?\n\nA model command in this workspace that starts this profile's gh gets the host's token as GH_TOKEN and network access. It still needs the workspace's command and task networking preferences; under Allow for both it runs without asking. gh sends the token to github.com only.",
named(profile),
named(host),
),
}
}

/// The native confirmation for removing a toolchain profile. `workspaces`
/// holds, for each workspace it is assigned to, the workspace folder and the
/// display-safe folders of the grants the removal releases there.
Expand Down Expand Up @@ -822,6 +862,88 @@ impl DesktopService {
})
}

/// `settings` only. After a native confirmation that names the workspace,
/// the profile, and the review host, bind the profile's `gh` to the host's
/// token (ADR-0147). The binding is configuration: a model command of the
/// profile still needs the workspace's command and task-network
/// preferences and its approval. No token is read or shown here.
///
/// # Errors
///
/// `unknown_workspace`; `control` for an unknown profile or host, a
/// profile not assigned to the workspace, or a host whose kind is not
/// `github`; `cancelled`; `stale_revision`; `settings_change_running`;
/// `busy`.
pub fn settings_bind_gh_token(
&self,
request: GhTokenBindRequest,
prompt: &dyn SettingsPrompt,
) -> Result<SettingsOverview, DesktopError> {
let _guard = ChangeGuard::take(&self.inner.settings_change)?;
check_name(&request.profile)?;
check_name(&request.host)?;
let (workspace_id, confirmation) = {
let store = self.inner.open_or_create_control()?;
check_revision(&store, request.revision)?;
let workspace = store
.registered_workspace(request.workspace_id)
.ok_or_else(DesktopError::unknown_workspace)?;
let profile = store
.profile(&request.profile)
.ok_or_else(|| DesktopError::from_control(&ControlError::UnknownProfile))?
.profile()
.name()
.to_owned();
let host = store
.review_host(&request.host)
.ok_or_else(|| DesktopError::from_control(&ControlError::UnknownReviewHost))?
.name()
.to_owned();
let confirmation = bind_gh_token_confirmation(
&folder_of_directory(workspace.directory_path()),
&profile,
&host,
);
(workspace.id(), confirmation)
};
confirm(prompt, &confirmation)?;
self.apply(|store| {
store
.bind_gh_token(
workspace_id,
&request.profile,
&request.host,
request.revision,
)
.map(|_| ())
})
}

/// `settings` only. End a profile's GitHub token binding (ADR-0147).
/// Unbinding narrows access, so no dialog opens (ADR-0115). The runs that
/// used the binding are stopped, and the call waits for them as other
/// settings changes do.
///
/// # Errors
///
/// `unknown_workspace`; `control` for an unknown profile or one with no
/// binding; `stale_revision`; `settings_change_running`; `busy`;
/// `runs_not_stopped`; `runs_unchecked`.
pub fn settings_unbind_gh_token(
&self,
request: GhTokenUnbindRequest,
) -> Result<SettingsOverview, DesktopError> {
let _guard = ChangeGuard::take(&self.inner.settings_change)?;
check_name(&request.profile)?;
self.apply(|store| {
let workspace_id = store
.registered_workspace(request.workspace_id)
.map(|workspace| workspace.id())
.ok_or(ControlError::UnknownWorkspace)?;
store.unbind_gh_token(workspace_id, &request.profile, request.revision)
})
}

/// `settings` only. After a native confirmation that lists the origins
/// core parsed, record a package-network profile as `omgcode workspace
/// package-profile-add` does. The profile is configuration only: no run
Expand Down
13 changes: 13 additions & 0 deletions crates/omgcode-app/src/desktop/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,9 @@ pub struct WorkspaceSettingsView {
/// The names of the toolchain profiles assigned to the workspace, in the
/// order assigned (ADR-0107). Only these can run in it.
pub profiles: Vec<String>,
/// The workspace's GitHub token bindings (ADR-0147), in the order made.
/// Names only.
pub gh_token_bindings: Vec<GhTokenBindingView>,
/// Display-safe text of the selected package cache root, if any.
pub package_cache_root: Option<String>,
/// The workspace's custom instructions (ADR-0080), empty when none are
Expand All @@ -1216,6 +1219,16 @@ pub struct WorkspaceSettingsView {
pub instructions_max_bytes: Option<usize>,
}

/// One toolchain profile of a workspace bound to a review host's token
/// (ADR-0147). Names only: never a token or a credential identifier.
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct GhTokenBindingView {
/// The toolchain profile's name.
pub profile: String,
/// The review host's name.
pub host: String,
}

/// Whether the Git tools are offered for a workspace, as the `settings` window
/// shows it (ADR-0139). Read from recorded grants and the program's file; it
/// says nothing about the workspace's preferences, and starts nothing.
Expand Down
Loading
Loading