launch

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package launch 是 CLI 与 UI 共用的「后台发射器」:以独立会话(setsid)self-exec 出一个 `conduct workflow run <name> --cwd <dir>` 前台子进程、经 stdin 喂入用户需求,再有界等待子进程 落下初始 run.json,把可用 run id 交回调用方。

被 `conduct ui` 的 HTTP 启动路径与 `conduct workflow run -d` 复用——两者由此得到逐字节同构的 后台 run(pid 判活 / interrupted 语义一致)。发射细节每条都有踩坑背书,见 docs/specs/ui.md〈启动运行机制〉与 docs/specs/cli-runtime.md〈后台运行〉。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Launcher

type Launcher struct {
	// contains filtered or unexported fields
}

Launcher 持有一次后台发射所需的依赖:自身可执行文件路径(self-exec)、运行记录 store(确认落定)、 会话私有 stderr 临时目录(兜底子进程写 run.json 前就失败)、可注入时钟(便于测试)。

func NewLauncher

func NewLauncher(exePath string, store RunStore, stderrDir string, now func() time.Time) *Launcher

NewLauncher 构造发射器;now 传 nil 时用 time.Now。

func (*Launcher) Launch

func (l *Launcher) Launch(name, userPrompt, absCwd string) (runID, note string, err error)

Launch 发射一次运行并确认其初始 run.json。三种结果互斥:

  • runID != "":已确认,run id 可被 run list / run show 查到;
  • runID == "" 且 note != "" 且 err == nil:已发射但有界等待内未确认(子进程仍存活), 由调用方决定这算不算成功(UI 视作 202 回执,CLI 视作退 1);
  • err != nil:spawn 失败,或子进程在写 run.json 前就死了。

absCwd 须为调用方已校验过的绝对工作目录(发射器只管发射,不重做预检)。

func (*Launcher) LaunchResume

func (l *Launcher) LaunchResume(id string) (runID, note string, err error)

LaunchResume 后台恢复一次 failed / interrupted 运行:spawn 一个前台 `conduct run resume <id>` 子进程(不递归 -d), 有界等待其接管——因续写原 run,run id 即入参 <id>、无需 matchRunID 轮询,改以「run.json 的 pid 被 改成子进程 pid」判定子进程已接管(resume 重建串联态后把 status 改回 running、更新 pid 即落此签名)。 三态返回与 Launch 一致(见其文档)。调用方须已做「派生态为 failed / interrupted」的前置校验。

type RunStore

type RunStore interface {
	ListRuns() ([]*run.Record, []error, error)
	LoadRun(id string) (*run.Record, error)
}

RunStore 是发射器确认子进程落定所需的最小 store 能力:workflow run 靠 ListRuns 组合匹配刚发射的 run(matchRunID);run resume 续写原 run、run id 即入参,靠 LoadRun 确认子进程已接管(pid 更新)。 *store.Store 天然满足。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL