Move harness profiles between host and Docker and stop silent draft retargeting
Native installs left Docker-era harness profiles in harnesses.json, so every authoring launch failed trying to reach a Docker service, and a retained draft bound to the old Docker server was silently projected onto the configured one. - harness: add Profile.Mode and VerifyDockerLink as the single mode/verification helpers. `harness setup --host` configures or converts a host profile and clears docker_directory; reconfiguring a Docker-linked profile re-verifies the recorded directory still owns compose.yaml and fails naming it instead of saving a link that cannot launch. Setup's summary and `harness list` (via the new List/ListView shape) report the resulting mode and, for Docker, the directory, without changing the stored Config schema. - setup-native.py: after build/install-skill it writes host (no docker_directory) profiles for the detected harnesses, defaulting to the detected OpenCode profile rather than a stale pi default, taking models from --model or the existing valid profile and never inventing one; it clears a stale Docker link and preserves unrelated keys/profiles. Detection-only: no harness install, upgrade or download. - draft: add Draft.Resolve, the shared mismatch helper, which projects a draft onto the configured server and returns a dual-URL notice. CLI validate/submit and the TUI draft browser use it so a foreign draft is never silently retargeted; the TUI pre-wraps the notice to the panel width. - Tests cover the Docker->host and host->host transitions, the missing-directory failure, installer write/migration (Python), and the CLI/TUI notice, using the real config file path in a temp dir. - Update help text, README, docs and the packaged authoring skill reference to describe host as the default and the Docker-linked case.
This commit is contained in:
+29
-11
@@ -38,28 +38,38 @@ func (m Model) openDrafts() (tea.Model, tea.Cmd) {
|
||||
func (m *Model) loadDraftPreview() {
|
||||
m.draftTop = 0
|
||||
m.draftSource = ""
|
||||
m.draftNotice = ""
|
||||
if len(m.draftItems) == 0 {
|
||||
return
|
||||
}
|
||||
source, err := draft.Read(m.draftItems[m.draftIndex].Path)
|
||||
_, source, notice, err := m.readDraft(m.draftIndex)
|
||||
if err != nil {
|
||||
m.draftError = err.Error()
|
||||
return
|
||||
}
|
||||
m.draftSource = source
|
||||
m.draftNotice = notice
|
||||
}
|
||||
|
||||
func (m Model) selectedDraft() (draft.Draft, string, error) {
|
||||
if len(m.draftItems) == 0 {
|
||||
return draft.Draft{}, "", fmt.Errorf("no drafts")
|
||||
}
|
||||
d, err := draft.Load(m.draftItems[m.draftIndex].Path)
|
||||
// readDraft loads one retained draft's metadata and source once, projecting it
|
||||
// onto the configured server. It returns the shared dual-URL notice when the
|
||||
// draft was created against a different server so no caller silently retargets
|
||||
// a foreign draft.
|
||||
func (m *Model) readDraft(index int) (draft.Draft, string, string, error) {
|
||||
d, err := draft.Load(m.draftItems[index].Path)
|
||||
if err != nil {
|
||||
return d, "", err
|
||||
return d, "", "", err
|
||||
}
|
||||
d = d.ForServer(m.url)
|
||||
d, notice := d.Resolve(m.url)
|
||||
source, err := draft.Read(d.Path)
|
||||
return d, source, err
|
||||
return d, source, notice, err
|
||||
}
|
||||
|
||||
func (m Model) selectedDraft() (draft.Draft, string, string, error) {
|
||||
if len(m.draftItems) == 0 {
|
||||
return draft.Draft{}, "", "", fmt.Errorf("no drafts")
|
||||
}
|
||||
return m.readDraft(m.draftIndex)
|
||||
}
|
||||
|
||||
func (m Model) updateDrafts(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
@@ -123,11 +133,12 @@ func (m Model) updateDrafts(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
case "k", "up":
|
||||
m.draftTop = max(0, m.draftTop-1)
|
||||
case "enter", "e", "s", "v":
|
||||
d, source, err := m.selectedDraft()
|
||||
d, source, notice, err := m.selectedDraft()
|
||||
if err != nil {
|
||||
m.draftError = err.Error()
|
||||
return m, nil
|
||||
}
|
||||
m.draftNotice = notice
|
||||
switch msg.String() {
|
||||
case "enter", "e":
|
||||
return m.confirmMutation("Edit retained draft?", func() tea.Cmd { return editDraftMode(d.Name, source, true, d.CreateOnly, d) })
|
||||
@@ -173,7 +184,14 @@ func (m Model) draftsView(height int) string {
|
||||
if name == "" {
|
||||
name = "Unnamed draft"
|
||||
}
|
||||
lines := []string{fmt.Sprintf("Drafts · %d/%d · %s", m.draftIndex+1, len(m.draftItems), name), d.Path, fmt.Sprintf("Create-only: %t · Base version: %d", d.CreateOnly, d.BaseVersion), m.draftError, ""}
|
||||
lines := []string{fmt.Sprintf("Drafts · %d/%d · %s", m.draftIndex+1, len(m.draftItems), name), d.Path, fmt.Sprintf("Create-only: %t · Base version: %d", d.CreateOnly, d.BaseVersion)}
|
||||
if m.draftNotice != "" {
|
||||
// Pre-wrap the dual-URL notice to the panel width: fitBlock truncates a
|
||||
// single long line, so an unwrapped notice would cut off the configured
|
||||
// endpoint and the TUI would not actually name both servers.
|
||||
lines = append(lines, strings.Split(ansi.Wrap("Warning: "+m.draftNotice, max(1, m.width), ""), "\n")...)
|
||||
}
|
||||
lines = append(lines, m.draftError, "")
|
||||
source := strings.Split(m.draftSource, "\n")
|
||||
rows := max(0, height-len(lines)-1)
|
||||
top := min(m.draftTop, max(0, len(source)-rows))
|
||||
|
||||
@@ -191,3 +191,42 @@ func TestDraftBrowserAcceptsOtherServerAndKeepsUnnamedDraft(t *testing.T) {
|
||||
t.Fatal("unnamed draft submitted")
|
||||
}
|
||||
}
|
||||
|
||||
// TestDraftBrowserNoticeNamesBothServersForForeignDraft covers the stale 8081
|
||||
// draft case in the TUI: the selected foreign draft is projected onto the
|
||||
// configured server (create-only) and a notice names both endpoints instead of
|
||||
// silently retargeting it.
|
||||
func TestDraftBrowserNoticeNamesBothServersForForeignDraft(t *testing.T) {
|
||||
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
|
||||
foreign := "ws://127.0.0.1:8081/connect"
|
||||
configured := "ws://127.0.0.1:8080/connect"
|
||||
d, err := draft.Create("wrong", "source", foreign, true, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := New(context.Background(), configured)
|
||||
updated, _ := m.openDrafts()
|
||||
m = updated.(Model)
|
||||
if !strings.Contains(m.draftNotice, foreign) || !strings.Contains(m.draftNotice, configured) {
|
||||
t.Fatalf("preview notice did not name both servers: %q", m.draftNotice)
|
||||
}
|
||||
// The notice must name both endpoints at any realistic panel width: an
|
||||
// unwrapped line is truncated by fitBlock and loses the configured URL.
|
||||
for _, width := range []int{60, 100} {
|
||||
view := m
|
||||
view.width, view.height = width, 24
|
||||
rendered := view.View()
|
||||
if !strings.Contains(rendered, foreign) || !strings.Contains(rendered, configured) {
|
||||
t.Fatalf("notice at width %d did not name both servers:\n%s", width, rendered)
|
||||
}
|
||||
}
|
||||
updated, _ = m.updateDrafts(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'s'}})
|
||||
m = updated.(Model)
|
||||
if !m.confirmOpen || m.pendingDraft == nil || !m.pendingDraft.createOnly || m.pendingDraft.baseVersion != 0 {
|
||||
t.Fatalf("foreign draft was not projected as create-only: %+v", m.pendingDraft)
|
||||
}
|
||||
if !strings.Contains(m.draftNotice, foreign) || !strings.Contains(m.draftNotice, configured) {
|
||||
t.Fatalf("submit lost the dual-URL notice: %q", m.draftNotice)
|
||||
}
|
||||
_ = d
|
||||
}
|
||||
|
||||
+104
-104
@@ -95,110 +95,110 @@ func (k keyMap) ShortHelp() []key.Binding {
|
||||
func (k keyMap) FullHelp() [][]key.Binding { return [][]key.Binding{k.ShortHelp()} }
|
||||
|
||||
type Model struct {
|
||||
editorCheckGeneration uint64
|
||||
editorChecking bool
|
||||
statusOpen bool
|
||||
statusTop int
|
||||
statusRequest, statusError string
|
||||
systemStatus *protocol.SystemStatus
|
||||
usage *protocol.UsageStats
|
||||
draftOpen bool
|
||||
draftItems []draft.Draft
|
||||
draftIndex, draftTop int
|
||||
draftError, draftSource string
|
||||
ctx context.Context
|
||||
url string
|
||||
conn *websocket.Conn
|
||||
status string
|
||||
nextID uint64
|
||||
lines []string
|
||||
width int
|
||||
height int
|
||||
help help.Model
|
||||
keys keyMap
|
||||
pipelines []protocol.PipelineSummary
|
||||
loaded bool
|
||||
notificationEndpoints []protocol.NotificationEndpoint
|
||||
logSeen []bool
|
||||
unread int
|
||||
logOpen bool
|
||||
logTop int
|
||||
logPan int
|
||||
paletteOpen bool
|
||||
commandInput textinput.Model
|
||||
commandIndex int
|
||||
homeTop int
|
||||
searchOpen bool
|
||||
detail *protocol.PipelineDetail
|
||||
detailRequest string
|
||||
detailLoading bool
|
||||
detailError string
|
||||
pipelineTop int
|
||||
graphPan int
|
||||
versionsOpen bool
|
||||
versionIndex int
|
||||
confirmOpen bool
|
||||
actionConfirm *protocol.Message
|
||||
actionConfirmTop int
|
||||
actionApproved bool
|
||||
defaultModel string
|
||||
defaultHarness string
|
||||
editorDebugRunID int64
|
||||
mutationTitle string
|
||||
mutationCommand func() tea.Cmd
|
||||
mutationTop int
|
||||
pendingDraft *editedMsg
|
||||
draftNameInput textinput.Model
|
||||
submitID string
|
||||
submitNotice string
|
||||
stageIndex int
|
||||
stageTop int
|
||||
stageFocus bool
|
||||
stageConfigExpanded bool
|
||||
reconnecting bool
|
||||
requestedPipelineID int64
|
||||
requestedVersion int
|
||||
runs []protocol.RunSummary
|
||||
runDetail *protocol.RunDetail
|
||||
runOpen bool
|
||||
runForm int
|
||||
runInput textinput.Model
|
||||
runPrompt textarea.Model
|
||||
runWorkspace string
|
||||
cliRun, cliStarted, runPicker bool
|
||||
cliOptions RunOptions
|
||||
runPickerIndex int
|
||||
runPickerInput textinput.Model
|
||||
runTask string
|
||||
runPaths []string
|
||||
runIndex, runTop int
|
||||
requestedRunID int64
|
||||
runStartRequest string
|
||||
runStepIndex int
|
||||
runDetailFocus bool
|
||||
runCollapsed map[string]bool
|
||||
runError string
|
||||
runPipelineID int64
|
||||
runFailedOnly bool
|
||||
runSearch textinput.Model
|
||||
runSearchOpen bool
|
||||
runGraphFocus bool
|
||||
runGraphTop int
|
||||
runGraphPan int
|
||||
editorOpen bool
|
||||
editorInput textinput.Model
|
||||
editorIndex int
|
||||
editorDraft *editedMsg
|
||||
draftDeletingPath string
|
||||
draftDeletingTop int
|
||||
runSpinner spinner.Model
|
||||
templates []protocol.Template
|
||||
templateOpen, templateRaw bool
|
||||
templateGraphFocus, templateConfirm bool
|
||||
templateGraphTop, templateGraphPan int
|
||||
templateIndex, templateTop int
|
||||
templateLines []string
|
||||
templateRequest, templateError string
|
||||
editorCheckGeneration uint64
|
||||
editorChecking bool
|
||||
statusOpen bool
|
||||
statusTop int
|
||||
statusRequest, statusError string
|
||||
systemStatus *protocol.SystemStatus
|
||||
usage *protocol.UsageStats
|
||||
draftOpen bool
|
||||
draftItems []draft.Draft
|
||||
draftIndex, draftTop int
|
||||
draftError, draftSource, draftNotice string
|
||||
ctx context.Context
|
||||
url string
|
||||
conn *websocket.Conn
|
||||
status string
|
||||
nextID uint64
|
||||
lines []string
|
||||
width int
|
||||
height int
|
||||
help help.Model
|
||||
keys keyMap
|
||||
pipelines []protocol.PipelineSummary
|
||||
loaded bool
|
||||
notificationEndpoints []protocol.NotificationEndpoint
|
||||
logSeen []bool
|
||||
unread int
|
||||
logOpen bool
|
||||
logTop int
|
||||
logPan int
|
||||
paletteOpen bool
|
||||
commandInput textinput.Model
|
||||
commandIndex int
|
||||
homeTop int
|
||||
searchOpen bool
|
||||
detail *protocol.PipelineDetail
|
||||
detailRequest string
|
||||
detailLoading bool
|
||||
detailError string
|
||||
pipelineTop int
|
||||
graphPan int
|
||||
versionsOpen bool
|
||||
versionIndex int
|
||||
confirmOpen bool
|
||||
actionConfirm *protocol.Message
|
||||
actionConfirmTop int
|
||||
actionApproved bool
|
||||
defaultModel string
|
||||
defaultHarness string
|
||||
editorDebugRunID int64
|
||||
mutationTitle string
|
||||
mutationCommand func() tea.Cmd
|
||||
mutationTop int
|
||||
pendingDraft *editedMsg
|
||||
draftNameInput textinput.Model
|
||||
submitID string
|
||||
submitNotice string
|
||||
stageIndex int
|
||||
stageTop int
|
||||
stageFocus bool
|
||||
stageConfigExpanded bool
|
||||
reconnecting bool
|
||||
requestedPipelineID int64
|
||||
requestedVersion int
|
||||
runs []protocol.RunSummary
|
||||
runDetail *protocol.RunDetail
|
||||
runOpen bool
|
||||
runForm int
|
||||
runInput textinput.Model
|
||||
runPrompt textarea.Model
|
||||
runWorkspace string
|
||||
cliRun, cliStarted, runPicker bool
|
||||
cliOptions RunOptions
|
||||
runPickerIndex int
|
||||
runPickerInput textinput.Model
|
||||
runTask string
|
||||
runPaths []string
|
||||
runIndex, runTop int
|
||||
requestedRunID int64
|
||||
runStartRequest string
|
||||
runStepIndex int
|
||||
runDetailFocus bool
|
||||
runCollapsed map[string]bool
|
||||
runError string
|
||||
runPipelineID int64
|
||||
runFailedOnly bool
|
||||
runSearch textinput.Model
|
||||
runSearchOpen bool
|
||||
runGraphFocus bool
|
||||
runGraphTop int
|
||||
runGraphPan int
|
||||
editorOpen bool
|
||||
editorInput textinput.Model
|
||||
editorIndex int
|
||||
editorDraft *editedMsg
|
||||
draftDeletingPath string
|
||||
draftDeletingTop int
|
||||
runSpinner spinner.Model
|
||||
templates []protocol.Template
|
||||
templateOpen, templateRaw bool
|
||||
templateGraphFocus, templateConfirm bool
|
||||
templateGraphTop, templateGraphPan int
|
||||
templateIndex, templateTop int
|
||||
templateLines []string
|
||||
templateRequest, templateError string
|
||||
}
|
||||
|
||||
func New(ctx context.Context, url string) Model {
|
||||
|
||||
Reference in New Issue
Block a user