Make Pipelines Docker-only with OpenCode and Pi
Install current verified harness releases inside Docker, preserve persistent accounts and settings, and provide separate interactive and pipeline model defaults with terminal onboarding and fuzzy pickers. Add Docker-aware authoring transport, Pi stage execution, bounded workflow controls, reliable final-result readback and usage settlement, and finite short-lived CLI pipe draining. Keep dated installation evidence and packaged authoring guidance consistent. Verified with a real Docker installation, both harness stages and interactive authors, the built-in plan/implement/review starter, independent host race/vet checks, installer tests, and packaged skill tests. Generated release receipts stay ignored in clean checkouts.
This commit is contained in:
@@ -31,8 +31,15 @@ type OpenCodeClient struct {
|
||||
OnGenerationSession func(id, backend, reference string, active bool) error
|
||||
connection *opencode.Connection
|
||||
command func(context.Context, string, ...string) ([]byte, error)
|
||||
sessionPollInterval time.Duration // test seam; defaults to defaultSessionPollInterval
|
||||
}
|
||||
|
||||
// defaultSessionPollInterval bounds the delay between V2 active-session checks.
|
||||
// The V2 /api/experimental/session/{id}/wait request blocks server-side until the
|
||||
// CLI's own request timeout (observed ~6 minutes, HTTP 499) expires, which a long
|
||||
// agent stage exceeds; short active-session polls avoid that timeout.
|
||||
const defaultSessionPollInterval = time.Second
|
||||
|
||||
type openCodeError struct {
|
||||
operation string
|
||||
status int
|
||||
@@ -109,7 +116,7 @@ func (c OpenCodeClient) call(ctx context.Context, method, path string, body any)
|
||||
if c.command != nil {
|
||||
return c.command(ctx, directory, args...)
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, opencode.Executable(), args...)
|
||||
cmd := opencode.CommandContext(ctx, opencode.Executable(), args...)
|
||||
cmd.Dir = directory
|
||||
stdout := &boundedBuffer{limit: maxModelResponse}
|
||||
stderr := &boundedBuffer{limit: 8 << 10}
|
||||
@@ -130,7 +137,10 @@ func (c OpenCodeClient) call(ctx context.Context, method, path string, body any)
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
// Do not embed provider responses, prompts, credentials, or CLI logs in errors.
|
||||
return nil, &openCodeError{operation: method + " " + path, status: status, diagnostic: safeCommandDiagnostic(err, stdout.Bytes())}
|
||||
// Keep the raw cause so errors.Is(err, exec.ErrWaitDelay) still holds while
|
||||
// Error() stays sanitized. This branch is only reached with a non-nil Run
|
||||
// error, so valid-looking partial stdout is never returned as success.
|
||||
return nil, &openCodeError{operation: method + " " + path, status: status, cause: err, diagnostic: safeCommandDiagnostic(err, stdout.Bytes())}
|
||||
}
|
||||
if stdout.overflow {
|
||||
return nil, fmt.Errorf("OpenCode response exceeds 1 MiB limit")
|
||||
@@ -157,6 +167,63 @@ func safeCommandDiagnostic(err error, data []byte) string {
|
||||
return detail
|
||||
}
|
||||
|
||||
// activeSessionState is the documented GET /api/session/active entry shape:
|
||||
// {"data":{"ses_ID":{"type":"running"}}}. An absent session is inactive.
|
||||
type activeSessionState struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// waitForSessionIdle polls GET /api/session/active through the managed CLI until
|
||||
// the admitted session is absent (inactive). It is the single V2 wait helper used
|
||||
// by every V2 generation path; it never issues the long blocking .../wait request,
|
||||
// uses a context-aware delay with no busy loop, and fails closed on malformed,
|
||||
// non-object or unsupported responses instead of treating bad JSON as inactive.
|
||||
func (c OpenCodeClient) waitForSessionIdle(ctx context.Context, sessionID string) error {
|
||||
interval := c.sessionPollInterval
|
||||
if interval <= 0 {
|
||||
interval = defaultSessionPollInterval
|
||||
}
|
||||
for {
|
||||
active, err := c.sessionActive(ctx, sessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !active {
|
||||
return nil
|
||||
}
|
||||
timer := time.NewTimer(interval)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
timer.Stop()
|
||||
return ctx.Err()
|
||||
case <-timer.C:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sessionActive reports whether sessionID is currently active. Missing, null or
|
||||
// non-object data, and any state other than the documented "running" type, are
|
||||
// errors so a bad response can never be mistaken for a settled session.
|
||||
func (c OpenCodeClient) sessionActive(ctx context.Context, sessionID string) (bool, error) {
|
||||
data, err := c.call(ctx, "get", "/api/session/active", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
var response struct {
|
||||
Data map[string]activeSessionState `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &response); err != nil || response.Data == nil {
|
||||
return false, fmt.Errorf("%w: OpenCode returned an invalid active-session response", ErrHarnessTransport)
|
||||
}
|
||||
for _, state := range response.Data {
|
||||
if state.Type != "running" {
|
||||
return false, fmt.Errorf("%w: OpenCode reported an unsupported active-session state", ErrHarnessTransport)
|
||||
}
|
||||
}
|
||||
_, active := response.Data[sessionID]
|
||||
return active, nil
|
||||
}
|
||||
|
||||
func (c *OpenCodeClient) Generate(ctx context.Context, config ModelConfig, prompt string) (text string, err error) {
|
||||
if c.Operations != nil {
|
||||
c.Operations.Provider, c.Operations.Model = config.Provider, config.Model
|
||||
@@ -246,16 +313,14 @@ func (c *OpenCodeClient) Generate(ctx context.Context, config ModelConfig, promp
|
||||
if _, err = c.call(ctx, "post", "/api/session/"+session.Data.ID+"/prompt", generationBody("text", prompt, config, c.Backend)); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if _, err = c.call(ctx, "post", "/api/experimental/session/"+session.Data.ID+"/wait", nil); err != nil {
|
||||
if err = c.waitForSessionIdle(ctx, session.Data.ID); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var data []byte
|
||||
data, err = c.call(ctx, "get", "/api/session/"+session.Data.ID+"/message?order=desc&limit=100&type=assistant", nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
data, text, err = c.readFinalAgentResult(ctx, session.Data.ID)
|
||||
if len(data) > 0 {
|
||||
c.FormatAudit = string(data)
|
||||
}
|
||||
c.FormatAudit = string(data)
|
||||
text, err = completedAgentResult(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user