Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: support devcontainer agents in ui and unify backend#18332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 29 commits intomainfrommafredri/feat-agent-devcontainer-injection-6
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
29 commits
Select commitHold shift + click to select a range
765c2cf
backend
mafredriJun 10, 2025
4019358
ui-1
mafredriJun 10, 2025
452dbc9
backend-2
mafredriJun 10, 2025
6a23998
ui-2
mafredriJun 10, 2025
ee3ed36
backend-3
mafredriJun 11, 2025
fc1a90a
ui-3
mafredriJun 11, 2025
88ce78f
ui-wip
mafredriJun 11, 2025
b1431a3
ui-wip2
mafredriJun 13, 2025
2c2bf28
backend fix test after rebase
mafredriJun 13, 2025
18e1593
ui-final?
mafredriJun 13, 2025
df28ff9
oh no I accidentally the coercion
mafredriJun 13, 2025
9f69f69
site: remove circ dependency
mafredriJun 13, 2025
ecfe483
site: add tests
mafredriJun 13, 2025
71c61b6
whelp
mafredriJun 13, 2025
2e1c31f
tweak app display
mafredriJun 13, 2025
7e41c15
add port forward test
mafredriJun 13, 2025
79e1844
cleanup
mafredriJun 13, 2025
8ce0aec
dont show content (due to margin) when there are no apps
mafredriJun 16, 2025
d3bda05
rewrite styles as Tailwind CSS
mafredriJun 16, 2025
d4f208b
review comments
mafredriJun 16, 2025
7e5ede0
review comments
mafredriJun 16, 2025
7a3674a
add comment about idempotency
mafredriJun 16, 2025
c0607b1
switch -> if
mafredriJun 16, 2025
e1ea4bf
rename apps to agentapps
mafredriJun 16, 2025
f150bad
refactor to use mutation
mafredriJun 16, 2025
2b22ee2
adjust refetch trigger
mafredriJun 17, 2025
4b9d218
fix linter
mafredriJun 17, 2025
e021c8d
Update agent/agentcontainers/api.go
mafredriJun 17, 2025
0c44de8
clarify todo
mafredriJun 17, 2025
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
PrevPrevious commit
NextNext commit
backend-2
  • Loading branch information
@mafredri
mafredri committedJun 13, 2025
commit452dbc9b7545c391f14c071dc5ef20226c26fe8b
75 changes: 54 additions & 21 deletionsagent/agentcontainers/api.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -72,16 +72,17 @@ type API struct {
configFileModifiedTimes map[string]time.Time // By config file path.
recreateSuccessTimes map[string]time.Time // By workspace folder.
recreateErrorTimes map[string]time.Time // By workspace folder.
injectedSubAgentProcs map[string]subAgentProcess // Bycontainer ID.
injectedSubAgentProcs map[string]subAgentProcess // Byworkspace folder.
asyncWg sync.WaitGroup

devcontainerLogSourceIDs map[string]uuid.UUID // By workspace folder.
}

type subAgentProcess struct {
agent SubAgent
ctx context.Context
stop context.CancelFunc
agent SubAgent
containerID string
ctx context.Context
stop context.CancelFunc
}

// Option is a functional option for API.
Expand DownExpand Up@@ -586,7 +587,11 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
dc.Dirty = true
}

if _, injected := api.injectedSubAgentProcs[dc.Container.ID]; !injected && dc.Status == codersdk.WorkspaceAgentDevcontainerStatusRunning {
proc, injected := api.injectedSubAgentProcs[dc.WorkspaceFolder]
if injected && proc.containerID != dc.Container.ID {
injected = false // The container ID changed, we need to re-inject.
}
if !injected && dc.Status == codersdk.WorkspaceAgentDevcontainerStatusRunning {
err := api.injectSubAgentIntoContainerLocked(ctx, dc)
if err != nil {
logger.Error(ctx, "inject subagent into container failed", slog.Error(err))
Expand DownExpand Up@@ -660,10 +665,22 @@ func (api *API) getContainers() (codersdk.WorkspaceAgentListContainersResponse,
if len(api.knownDevcontainers) > 0 {
devcontainers = make([]codersdk.WorkspaceAgentDevcontainer, 0, len(api.knownDevcontainers))
for _, dc := range api.knownDevcontainers {
// Include the agent if it's been created (we're iterating over
// copies, so mutating is fine).
if dc.Container != nil {
if proc := api.injectedSubAgentProcs[dc.WorkspaceFolder]; proc.agent.ID != uuid.Nil && proc.containerID == dc.Container.ID {
dc.Agent = &codersdk.WorkspaceAgentDevcontainerAgent{
ID: proc.agent.ID,
Name: proc.agent.Name,
Directory: proc.agent.Directory,
}
}
}

devcontainers = append(devcontainers, dc)
}
slices.SortFunc(devcontainers, func(a, b codersdk.WorkspaceAgentDevcontainer) int {
return strings.Compare(a.ID.String(), b.ID.String())
return strings.Compare(a.Name, b.Name)
})
}

Expand DownExpand Up@@ -975,9 +992,25 @@ func (api *API) injectSubAgentIntoContainerLocked(ctx context.Context, dc coders
return xerrors.New("container is nil, cannot inject subagent")
}

logger := api.logger.With(
slog.F("devcontainer_id", dc.ID),
slog.F("devcontainer_name", dc.Name),
slog.F("workspace_folder", dc.WorkspaceFolder),
slog.F("config_path", dc.ConfigPath),
slog.F("container_id", container.ID),
slog.F("container_name", container.FriendlyName),
)

// Skip if subagent already exists for this container.
if _, injected := api.injectedSubAgentProcs[container.ID]; injected || api.closed {
return nil
if proc, injected := api.injectedSubAgentProcs[dc.WorkspaceFolder]; injected || api.closed {
if proc.containerID == container.ID {
return nil
}

// If the subagent is already injected but the container ID has
// changed, we need to inject it into the new container.
logger.Debug(ctx, "injecting subagent into new container")
proc.stop()
}

// Mark subagent as being injected immediately with a placeholder.
Expand DownExpand Up@@ -1010,13 +1043,6 @@ func (api *API) injectSubAgentIntoContainerLocked(ctx context.Context, dc coders
api.mu.Unlock()
defer api.mu.Lock() // Re-lock.

logger := api.logger.With(
slog.F("devcontainer_id", dc.ID),
slog.F("devcontainer_name", dc.Name),
slog.F("workspace_folder", dc.WorkspaceFolder),
slog.F("config_path", dc.ConfigPath),
)

arch, err := api.ccli.DetectArchitecture(ctx, container.ID)
if err != nil {
return xerrors.Errorf("detect architecture: %w", err)
Expand DownExpand Up@@ -1176,7 +1202,9 @@ func (api *API) runSubAgentInContainer(ctx context.Context, dc codersdk.Workspac
}

api.mu.Lock()
delete(api.injectedSubAgentProcs, container.ID)
if api.injectedSubAgentProcs[dc.WorkspaceFolder].containerID == container.ID {
delete(api.injectedSubAgentProcs, dc.WorkspaceFolder)
}
api.mu.Unlock()

logger.Debug(ctx, "agent process cleanup complete")
Expand All@@ -1191,10 +1219,11 @@ func (api *API) runSubAgentInContainer(ctx context.Context, dc codersdk.Workspac
return
}
// Update the placeholder with a valid subagent, context and stop.
api.injectedSubAgentProcs[container.ID] = subAgentProcess{
agent: agent,
ctx: agentCtx,
stop: agentStop,
api.injectedSubAgentProcs[dc.WorkspaceFolder] = subAgentProcess{
agent: agent,
containerID: container.ID,
ctx: agentCtx,
stop: agentStop,
}
api.mu.Unlock()

Expand DownExpand Up@@ -1226,7 +1255,11 @@ func (api *API) Close() error {
api.closed = true

for _, proc := range api.injectedSubAgentProcs {
api.logger.Debug(api.ctx, "canceling subagent process", slog.F("agent_name", proc.agent.Name), slog.F("agent_id", proc.agent.ID))
api.logger.Debug(api.ctx, "canceling subagent process",
slog.F("agent_name", proc.agent.Name),
slog.F("agent_id", proc.agent.ID),
slog.F("container_id", proc.containerID),
)
proc.stop()
}

Expand Down
18 changes: 18 additions & 0 deletionscoderd/apidoc/docs.go
View file
Open in desktop

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

18 changes: 18 additions & 0 deletionscoderd/apidoc/swagger.json
View file
Open in desktop

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

9 changes: 9 additions & 0 deletionscodersdk/workspaceagents.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -422,6 +422,15 @@ type WorkspaceAgentDevcontainer struct {
Status WorkspaceAgentDevcontainerStatus `json:"status"`
Dirty bool `json:"dirty"`
Container *WorkspaceAgentContainer `json:"container,omitempty"`
Agent *WorkspaceAgentDevcontainerAgent `json:"agent,omitempty"`
}

// WorkspaceAgentDevcontainerAgent represents the sub agent for a
// devcontainer.
type WorkspaceAgentDevcontainerAgent struct {
ID uuid.UUID `json:"id" format:"uuid"`
Name string `json:"name"`
Directory string `json:"directory"`
}

// WorkspaceAgentContainer describes a devcontainer of some sort
Expand Down
5 changes: 5 additions & 0 deletionsdocs/reference/api/agents.md
View file
Open in desktop

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

29 changes: 29 additions & 0 deletionsdocs/reference/api/schemas.md
View file
Open in desktop

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

8 changes: 8 additions & 0 deletionssite/src/api/typesGenerated.ts
View file
Open in desktop

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


[8]ページ先頭

©2009-2025 Movatter.jp