plan

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 56 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package plan implements the services of plan.v1 on the store: projects, wishes and questions. Tasks, which run workers, are served by the harness package.

Index

Constants

View Source
const (
	ForgeGitHub = "github"
	ForgeGitLab = "gitlab"
)

Forges a babysit declaration may name.

View Source
const (
	// DefaultPageSize is the default number of items returned when page_size is not specified or <= 0.
	DefaultPageSize = 50
	// MaxPageSize is the maximum allowed page size.
	MaxPageSize = 200
)
View Source
const (
	DefaultMergeMain        = planv1.MergeMain_MERGE_MAIN_RELEASE
	DefaultMergeMainEvery   = time.Hour
	DefaultInstallQuestions = planv1.InstallQuestions_INSTALL_QUESTIONS_ALWAYS
)

Defaults of keeping a wish's integration branch up with the project's main branch: merged at each release, main fetched at most hourly, and a release of Djinn installed by itself on main.

View Source
const (
	DefaultQuestionModel     = "sonnet" // for claude; another provider's own default
	DefaultQuestionBudgetUSD = 2.0
)

Defaults of the question workers: a cheaper model is enough to read and revise a question; and a cap, so that one never runs long.

View Source
const DefaultBranch = "{code}-{slug}-{uuid8}"

DefaultBranch is the branch template of a project whose files set none.

View Source
const DefaultCorrectionAttempts = 2

DefaultCorrectionAttempts is how many correction workers Djinn starts for a failed integration, one after the other, before it asks the person, in a project whose files set none.

View Source
const DefaultTilasmBytes = 50 << 20

DefaultTilasmBytes is the ceiling of a new tilasm, its files summed: material to read, not a store of videos.

View Source
const HistoryHeader = "## Historique des versions pr\u00e9c\u00e9dentes"

HistoryHeader introduces the prior-versions section appended to a revised question's context.

View Source
const LeadAgyProjectID = "djinn-lead"

LeadAgyProjectID is the id of the Antigravity project Djinn writes for the lead session.

View Source
const LeadFirstFile = "lead-first.md"

LeadFirstFile holds the first message of a new lead, in the wish's folder of Djinn's data folder, next to its page: the lead reads it there when the shell cannot carry it.

View Source
const LeadTerminal = "lead"

LeadTerminal is the name of the terminal of the lead.

View Source
const MaxActive = 3

MaxActive is how many wishes are active at once, at most. A djinn grants three wishes: the limit guards the user's attention, not the machine, and no option changes it. There may be as many wishes as you like: the three first are active, the others wait paused, their workers stopped.

View Source
const PageFile = "page.html"

PageFile is the name of a wish's synced page.

View Source
const PagesDir = "wishes"

PagesDir is the folder of the synced pages in the data directory: one folder per wish, named by its id, holding page.html.

View Source
const PlanDir = "plan"

PlanDir is the folder of a project that holds its plan files.

View Source
const QuestionShape = "A question's `--context` reads at a glance, in this order. First, every command the " +
	"developer must run, in one fenced code block, in run order, a `# …` comment above each command saying what it " +
	"prints and what to expect; fence it with `~~~` lines, which need no backtick (between double quotes, backticks " +
	"run as a command). Then short Markdown: a one-line why; a few bullets of facts, each saying whether it is " +
	"verified; the decision, with what each option changes and costs. No command, flag, path or hash inside a " +
	"sentence: it goes in the code block (a branch or a commit as a `#` comment) or in a table. No wall of text: " +
	"short paragraphs, lists, tables and code blocks, which the window renders. `djinn question ask` and `djinn " +
	"question revise` print a warning for each break of this shape: revise the context at once."

QuestionShape is the shape of a question's context, the same for every agent that asks or revises one: the lead reads it in its brief, a worker at the end of its first prompt, an investigator in its own. The developer, 13/10 (W575), got revisions whose commands to run were lost in a wall of text. ContextWarnings checks it.

View Source
const SkillFile = "SKILL.md"

SkillFile is the file that makes a folder a skill.

View Source
const (
	// SourceEvery is the least time between two starts of a source's command, by default.
	SourceEvery = 5 * time.Minute
)

How often a source runs.

View Source
const TilasmPolicy = "default-src 'none'; " +
	"script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:; " +
	"style-src 'self' 'unsafe-inline'; " +
	"img-src 'self' data: blob:; " +
	"font-src 'self' data:; " +
	"media-src 'self' data: blob:; " +
	"worker-src 'self' blob:; " +
	"frame-src 'self'; " +
	"connect-src 'none'; " +
	"object-src 'none'; " +
	"base-uri 'self'; " +
	"form-action 'none'; " +
	"frame-ancestors 'self'; " +
	"sandbox allow-scripts"

TilasmPolicy is the content security policy of a tilasm's files, sent with each. Its own scripts run, inline or from its files, and its styles, images, fonts and media load from its files or data: and blob: addresses. It reaches no network: connect-src 'none' refuses fetch, XMLHttpRequest, WebSocket and EventSource, default-src 'none' every other load from elsewhere, form-action 'none' a form. sandbox gives it an opaque origin even opened alone in a browser: it never shares Djinn's, so it reads neither Djinn's cookie nor its storage, and calls none of its services. Only Djinn's own pages may frame it.

A link the tilasm follows can still navigate its own frame away: a policy cannot forbid that. Each answer names the server's own origin beside 'self' (tilasmPolicy).

Variables

View Source
var AgyProjectsDir = func() (string, error) {
	if os.Getenv("DJINN_TEST") == "1" {
		if h := os.Getenv("DJINN_HOME"); h != "" {
			return filepath.Join(h, "agy-projects"), nil
		}
		return filepath.Join(os.TempDir(), "djinn-test-agy-projects"), nil
	}
	home, err := os.UserHomeDir()
	if err != nil {
		return "", err
	}
	return filepath.Join(home, ".gemini", "config", "projects"), nil
}

AgyProjectsDir is the folder of Antigravity's projects, ~/.gemini/config/projects; tests override it.

View Source
var ErrNoChoice = errors.New("the lead no longer shows this choice")

ErrNoChoice says that the lead's terminal no longer shows the choice the window showed: answered there, or changed.

View Source
var ErrNoLead = errors.New("this wish has no lead to tell")

ErrNoLead says that a wish has no lead to tell: no session is recorded for it, or its lead does not run and the wish is not active. What the lead missed waits in the wish's brief.

View Source
var ErrNoProject = errors.New("no project has a folder on this machine, and Djinn never starts a lead in your home " +
	"folder: create a project first (djinn project add <folder>, or + beside Projects in the window)")

ErrNoProject says that no project has a folder on this machine: a lead has nowhere to start, and Djinn never starts one in the home folder.

View Source
var ErrUpToDate = errors.New("nothing to push: the remote is up to date")

ErrUpToDate says that a push found nothing to push: the remote holds the branch already.

View Source
var LeadCommands = []string{
	"djinn",
	"git status",
	"git log",
	"git diff",
	"git show",
	"git branch",
}

LeadCommands are the safe commands a lead session is pre-authorized to run without prompting the developer: Djinn's own CLI and read-only Git commands.

View Source
var SettingsFile = filepath.Join(".agents", "settings.txtpb")

SettingsFile is where a project's repository keeps the settings its team shares: a plan.v1.ProjectSettings in text protobuf, next to the permissions in .agents.

View Source
var SkillFolders = []string{filepath.Join(".agents", "skills"), filepath.Join(".claude", "skills")}

SkillFolders are where a project keeps its skills, in this order: .agents/skills, which every agent reads, then .claude/skills. A name found in the first hides the same name in the second.

View Source
var Validate = connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
	return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
		if m, ok := req.Any().(proto.Message); ok {
			if err := protovalidate.Validate(m); err != nil {
				return nil, connect.NewError(connect.CodeInvalidArgument, err)
			}
		}
		return next(ctx, req)
	}
})

Validate checks every unary request against the rules of its proto, as the command line did before sending it.

View Source
var WorkerGuard = connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
	return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
		caller := CallerFromContext(ctx)
		if caller == nil {
			return next(ctx, req)
		}
		procedure := req.Spec().Procedure

		if procedure == planv1connect.WishServiceMakeProcedure {
			return nil, connect.NewError(connect.CodePermissionDenied, errors.New(
				"a worker cannot make a wish; to try a command by hand, start a Djinn of your own with its own data folder",
			))
		}

		switch procedure {
		case planv1connect.QuestionServiceAskProcedure:
			if r, ok := req.Any().(*planv1.QuestionServiceAskRequest); ok {
				if r.WishId == "" {
					r.WishId = caller.WishID
				} else if r.WishId != caller.WishID {
					return nil, connect.NewError(connect.CodePermissionDenied, fmt.Errorf(
						"a worker cannot ask a question in wish %s (its task is in wish %s)", r.WishId, caller.WishID,
					))
				}
				if r.TaskId == "" {
					r.TaskId = caller.TaskID
				} else if r.TaskId != caller.TaskID {
					return nil, connect.NewError(connect.CodePermissionDenied, fmt.Errorf(
						"a worker cannot ask a question for task %s (its own task is %s)", r.TaskId, caller.TaskID,
					))
				}
			}
			return next(ctx, req)

		case planv1connect.QuestionServiceReviseProcedure:
			if r, ok := req.Any().(*planv1.QuestionServiceReviseRequest); ok {
				if r.WishId == "" {
					r.WishId = caller.WishID
				} else if r.WishId != caller.WishID {
					return nil, connect.NewError(connect.CodePermissionDenied, fmt.Errorf(
						"a worker cannot revise a question in wish %s (its task is in wish %s)", r.WishId, caller.WishID,
					))
				}
				if r.TaskId == "" {
					r.TaskId = caller.TaskID
				} else if r.TaskId != caller.TaskID {
					return nil, connect.NewError(connect.CodePermissionDenied, fmt.Errorf(
						"a worker cannot revise a question for task %s (its own task is %s)", r.TaskId, caller.TaskID,
					))
				}
			}
			return next(ctx, req)

		case planv1connect.BlockServicePutProcedure:
			if r, ok := req.Any().(*planv1.BlockServicePutRequest); ok {
				if r.WishId == "" {
					r.WishId = caller.WishID
				} else if r.WishId != caller.WishID {
					return nil, connect.NewError(connect.CodePermissionDenied, fmt.Errorf(
						"a worker cannot put a block in wish %s (its task is in wish %s)", r.WishId, caller.WishID,
					))
				}
				if r.TaskId == "" {
					r.TaskId = caller.TaskID
				} else if r.TaskId != caller.TaskID {
					return nil, connect.NewError(connect.CodePermissionDenied, fmt.Errorf(
						"a worker cannot put a block for task %s (its own task is %s)", r.TaskId, caller.TaskID,
					))
				}
			}
			return next(ctx, req)

		case planv1connect.TaskServiceUpdateProcedure:
			if r, ok := req.Any().(*planv1.TaskServiceUpdateRequest); ok {
				if r.TaskId == "" {
					r.TaskId = caller.TaskID
				} else if r.TaskId != caller.TaskID {
					return nil, connect.NewError(connect.CodePermissionDenied, fmt.Errorf(
						"a worker can only update its own task (%s)", caller.TaskID,
					))
				}
			}
			return next(ctx, req)

		case planv1connect.TilasmServicePutProcedure:
			if r, ok := req.Any().(*planv1.TilasmServicePutRequest); ok {
				if r.Wish == "" {
					r.Wish = caller.WishID
				} else if r.Wish != caller.WishID {
					return nil, connect.NewError(connect.CodePermissionDenied, fmt.Errorf(
						"a worker cannot put a tilasm in wish %s (its task is in wish %s)", r.Wish, caller.WishID,
					))
				}
				if r.Author == "" {
					r.Author = caller.TaskID
				}
			}
			return next(ctx, req)
		}

		if isReadOnlyProcedure(procedure) {
			return next(ctx, req)
		}

		return nil, connect.NewError(connect.CodePermissionDenied, fmt.Errorf(
			"a worker cannot call %s; to try a command by hand, start a Djinn of your own with its own data folder", procedure,
		))
	}
})

WorkerGuard intercepts Connect RPC calls to enforce permissions for workers. A worker cannot make a wish, or execute mutating commands on wishes, tasks, or plans other than those permitted for workers (question ask, question revise, block put, task update of own task, tilasm put).

Functions

func Active

func Active(wish *planv1.Wish) bool

Active tells whether wish is active. A wish made before Djinn recorded states is.

func ActiveWishes

func ActiveWishes(ctx context.Context, r store.Reader) ([]*planv1.Wish, error)

ActiveWishes returns the active wishes by rank: the first one has priority, and the scheduler serves them in this order.

func AllowWatch added in v0.1.2

func AllowWatch(home, projectID, command string, revoke bool) ([]string, error)

AllowWatch adds command to the watcher commands the developer allows in the project, in their settings file in home, or takes it back with revoke: the commands allowed then. Its words are joined by single spaces, as a watcher's command is compared.

func AllowanceOf

func AllowanceOf(wish *planv1.Wish, projectID string) planv1.Allowance

AllowanceOf is the right wish allows its workers in the project projectID: ALLOWANCE_NONE when it allows none.

func AnswerLine

func AnswerLine(q *planv1.Question, did string) string

AnswerLine is the line that tells a lead the answer to q: the choice, the option and the note, on one line; then what Djinn did with it, when did says it settled it; or else that the lead turns it into tasks itself.

func ApprovedLine added in v0.1.1

func ApprovedLine(q *planv1.Question, by string) string

ApprovedLine is the line that tells a lead the developer approved the answer by gave q (you, or a worker's code): the decision is theirs now.

func Ask

func Ask(ctx context.Context, tx *store.Tx, question *planv1.Question) error

Ask stores question, new, in tx with the next code of its wish. The caller journals the command that asks it.

func AzimaBranchName added in v0.1.1

func AzimaBranchName(a *planv1.Task) string

AzimaBranchName is the branch of an azima under the per-azima push strategy: the one recorded when Djinn cut it or the developer named it (Azima.cut_from), else djinn/<code>-<slug of its title>, or djinn/<code>.

func AzimaDependenciesText added in v0.1.1

func AzimaDependenciesText(deps []AzimaDependency) string

AzimaDependenciesText says deps in a line: "T2 after T1; T3 after T1, T2".

func AzimaMergeRunning added in v0.1.1

func AzimaMergeRunning(azima *planv1.Task, tasks []*planv1.Task, branch string) string

AzimaMergeRunning says, in a phrase, what merges into branch, the own branch of azima among tasks, the tasks of its wish, now: a batch of work being merged into it, a correction or review worker of the azima bringing work into it, or one settling main's merge; "" when none does. While one runs, the azima's branch is not renamed under it.

func AzimaOf added in v0.1.1

func AzimaOf(t *planv1.Task, byID map[string]*planv1.Task) *planv1.Task

AzimaOf is the azima t is part of among byID, the tasks of its wish by id, walking up part_of: t itself when it is an azima; nil when none.

func BuildGlobalBrief added in v0.1.1

func BuildGlobalBrief(ctx context.Context, r store.Reader, home string) (string, error)

BuildGlobalBrief writes the brief of all wishes in Djinn: every active wish with its details, paused and granted wishes on one line each, then Djinn's rules once for all projects.

func CallerActor added in v0.1.1

func CallerActor(ctx context.Context) string

CallerActor returns the actor name for the journal. If ctx has a WorkerCaller, its TaskID is returned; otherwise the local user actor is returned.

func CanReadOnly added in v0.1.1

func CanReadOnly(p planv1.Provider) bool

CanReadOnly tells whether a provider can run a question worker (read-only).

func CanResume added in v0.1.1

func CanResume(p planv1.Provider) bool

CanResume reports whether a provider can resume an existing session.

func CarryLead added in v0.1.1

func CarryLead(ctx context.Context, s *store.Store) (*planv1.Lead, error)

CarryLead records the one lead from the leads the wishes kept before it, once: only while no lead is recorded. The lead of the first active wish by rank wins, else that of the most recent wish. It returns the lead recorded, nil when there was nothing to carry.

func ChangedLine added in v0.1.2

func ChangedLine(q *planv1.Question, was *planv1.Answer, did string) string

ChangedLine is AnswerLine for an answer that replaces was, another choice: the line says the developer changed it.

func CheckedOutBranch

func CheckedOutBranch(ctx context.Context, dir string) string

CheckedOutBranch is the branch the checkout in dir is on: "" when it is on none (a detached HEAD), or dir is not in Git, or git did not answer within readGitTimeout.

func ChecksText

func ChecksText(checks []*planv1.ProjectCheck) string

ChecksText lists checks on one line: "lint: go tool task lint (commit, push); test: go tool task test (push)".

func CleanContext added in v0.1.2

func CleanContext(context string) string

CleanContext strips any auto-appended HistoryHeader section from a question's context so revisions never nest or duplicate prior history.

func CloserWord

func CloserWord(c planv1.Closer) string

CloserWord names who marked a task done by hand.

func ClosesCycle added in v0.1.1

func ClosesCycle(task *planv1.Task, deps []string, azima string, tasks []*planv1.Task) string

ClosesCycle tells whether task, waiting for deps and part of azima, would reach itself through tasks, following what each task depends on and the azima it is part of, and then says the cycle in codes ("W1 → W3 → W1"); "" when it would not.

func CompareCodes

func CompareCodes(a, b string) int

CompareCodes orders task codes as a person reads them: by letter, then by number, T2 before T10.

func ContextWarnings added in v0.1.2

func ContextWarnings(context string) []string

ContextWarnings says how context, a question's Markdown, breaks QuestionShape, a line per fault; none when it keeps it. Cheap guesses, not a parser: Djinn stores a context as given, and its author revises it.

func CutNeeds added in v0.1.1

func CutNeeds(text string) (rest, needs string, ok bool)

CutNeeds splits a box's text from its needs: "(needs: …)", a parenthesis that opens on them, to its closing one. False when the box says none, or leaves the parenthesis open.

func Decision

func Decision(ctx context.Context, r store.Reader, wishID, ref string) (string, error)

Decision resolves the decision a task comes from, in wish wishID: an answered question by its code or its id, or a block of kind decision by its id. It returns what the task keeps: the question's code, or the block's id.

func DependencyAzimas added in v0.1.1

func DependencyAzimas(azima *planv1.Task, tasks []*planv1.Task) []*planv1.Task

DependencyAzimas finds all unique azimas that azima (or its work tasks) depends on among tasks.

func Description

func Description(dir string) string

Description is the description of the skill in dir, from the front matter of its SKILL.md: a line, or a folded block of indented lines; empty without one.

func DeveloperSettingsFile

func DeveloperSettingsFile(home, projectID string) string

DeveloperSettingsFile is where the developer keeps their own settings of a project, in Djinn's data folder home.

func DigestKeeps added in v0.1.1

func DigestKeeps(e *planv1.LeadEvent) bool

DigestKeeps tells whether a digest's line keeps the whole text of e, uncut.

func DigestLine added in v0.1.1

func DigestLine(e *planv1.LeadEvent) string

DigestLine is an event in a digest's line: its code, its kind, and its text in a few words.

func DoneLine

func DoneLine(t *planv1.WishTemplate, text string) string

DoneLine is the first line of text that says the template's work is done: a line that is done_when, or starts with it before a character that is not a letter nor a digit. Empty when none does.

func DoneLineOf added in v0.1.1

func DoneLineOf(done, text string) string

DoneLineOf is the first line of text that says done: a line that is done, or starts with it before a character that is not a letter nor a digit. Empty when none does, or done is.

func DoneWithProblems added in v0.1.1

func DoneWithProblems(t *planv1.Task) bool

DoneWithProblems tells a task whose worker ended done while its permissions refused some of its calls, with nobody to approve them (Task.refused): it may not have done its job. Nobody looked at it yet: a run again sets Task.refused anew, and marking it done (djinn task done, the developer or the lead) closes it as seen. Djinn proposes no grant while one is left: the lead heard of its refused calls and decides (Q273); the window shows a plain done.

func Downloads

func Downloads() (string, error)

Downloads returns the folder where files the user asked for land: the XDG download folder on Linux, which may have a translated name, else Downloads in the home folder, else the home folder itself.

func EffectiveWishPushStrategy added in v0.1.1

func EffectiveWishPushStrategy(ctx context.Context, r store.Reader, home string, wish *planv1.Wish) (planv1.PushStrategy, planv1.SettingSource, error)

EffectiveWishPushStrategy resolves the effective push strategy for wish in store r with home folder home.

func EnlightenLine

func EnlightenLine(q *planv1.Question, note, worker string) string

EnlightenLine is the line that tells a lead the developer wants to know more before answering q: what they want to know, as they typed it, on one line; then the question worker that investigates, when worker names one, or else that the lead does.

func Entities

func Entities() []proto.Message

Entities are the messages the store keeps: those of plan.v1, and what each command of a project costs.

func FiledLine

func FiledLine(wishID, from, text string) string

FiledLine is the line that tells the lead of the wish wishID that a request was filed in it, from the wish from.

func FillAzimas

func FillAzimas(tasks []*planv1.Task)

FillAzimas sets Task.azima on the azimas among tasks, from the tasks of their wish among tasks: give it every task of the wishes read. An azima is done when its status is and none of its parts is still to finish: a part that runs or waits keeps it in progress, whatever its plan file says. It is in progress when one of its parts has a worker on it or is done, or an azima part of it is under way; open otherwise. Once every part is finished, its azimas done or to validate in their turn, it is to validate (AWAITING_PROOF): nothing is left for Djinn, and the person checks its plan file's boxes (Task.proof_needs say what each one needs) and validates it. It is ready when every task it depends on is done.

func FillBabysit added in v0.1.1

func FillBabysit(watch string, number int, state string) string

FillBabysit fills the placeholders of a babysit's command line watch: {pr} and {mr} with number, {state} with the file state, each one word of it.

func FillTilasms

func FillTilasms(ctx context.Context, r store.Reader, tasks []*planv1.Task) error

FillTilasms sets Task.tilasms on tasks: the codes of the tilasms of their wish that cite each, in code order.

func FillTimes added in v0.1.1

func FillTimes(ctx context.Context, s *store.Store, tasks []*planv1.Task, now time.Time) error

FillTimes computes on the server and sets the durations on tasks: - running: the worker's process ran and did not wait for a gate; - waiting_gate: while running, the time it waited for a gate to be granted; - paused: every gap between the first start and now or the end where the task was not running; - waiting_before_start: the wait before the first start (from planned/create_time to first start, or to now). An azima's time sums its parts' work times.

func FindUnknownFields added in v0.1.1

func FindUnknownFields(b []byte, m proto.Message) []string

FindUnknownFields returns all unknown field names in text protobuf b when unmarshaled into m.

func Finished

func Finished(t *planv1.Task) bool

Finished tells a task of work finished: done, stopped on request, or cut short for good. Djinn resumes by itself every task it can (RESUMING), so one left interrupted (resumed as a fork, imported, its worktree gone) is history.

func FirstLine

func FirstLine(from, text string) string

FirstLine is the first line of the lead of a wish made for a request: the request, and where it comes from.

func FirstProjectFolder

func FirstProjectFolder(ctx context.Context, r store.Reader) (string, error)

FirstProjectFolder is the folder of the first of Djinn's projects, in the order the window lists them, that has one on this machine, outside the home folder's own. ErrNoProject when none has: where the window's terminal opens by default, and a new lead without a project of its own.

func GateCommand

func GateCommand(c *planv1.ProjectCheck) string

GateCommand is how an agent runs a check of the project: through the gate of its name.

func GivenByAPerson

func GivenByAPerson(n *planv1.ProofNeed) bool

GivenByAPerson tells whether a person can give the proof: its needs name a person or a review.

func Handlers

func Handlers(s *store.Store, opts ...Option) map[string]http.Handler

Handlers returns the Connect handlers of the plan services, by path prefix.

func HasUnfinishedParts added in v0.1.1

func HasUnfinishedParts(id string, tasks []*planv1.Task) bool

HasUnfinishedParts tells whether an azima has parts still to finish: work not finished, or an azima part of it not done.

func HoldsHome

func HoldsHome(dir string) bool

HoldsHome reports whether dir is the user's home folder or a folder above it (/, /home, C:\): Djinn never runs a lead there. An agent started there asks whether to trust the whole home folder, and reaches all of it.

func InboxFiledLine

func InboxFiledLine(wishID, source, text string) string

InboxFiledLine is the line that tells the lead of the wish wishID that an inbox item was filed in it.

func InboxFirstLine

func InboxFirstLine(source, text string) string

InboxFirstLine is the first line of the lead of a wish made for an inbox item: the item, and its source.

func InstallQuestionsWord added in v0.1.1

func InstallQuestionsWord(q planv1.InstallQuestions) string

InstallQuestionsWord is when Djinn asks to install builds, as the settings say it: always, when_needed, never.

func IntegrationBranchOf

func IntegrationBranchOf(wish *planv1.Wish, projectID string) string

IntegrationBranchOf is the branch wish integrates its finished work into in the project projectID; "" when none is recorded.

func Investigating

func Investigating(q *planv1.Question) bool

Investigating tells an open question whose last round is a request to investigate: it waits for the lead's revision, not for the developer.

func IsAzima

func IsAzima(t *planv1.Task) bool

IsAzima tells whether the task is an azima: no worker ever runs it.

func IsMerge added in v0.1.1

func IsMerge(t *planv1.Task) bool

IsMerge tells a correction or review worker.

func LeadWatchRule added in v0.1.1

func LeadWatchRule() string

LeadWatchRule is the brief's rule on djinn lead watch, with how each agent runs it.

func Linked

func Linked(ctx context.Context, r store.Reader, l link.Link) (string, error)

Linked is the wish a link shows: the tilasm's, or the wish itself. One not on this machine is an error of code NotFound.

func MadeLine added in v0.1.1

func MadeLine(wish *planv1.Wish, provisional bool) string

MadeLine is the line that tells the lead a wish was made from a request: it names it when its title is provisional, and plans it from its brief, which holds the request whole. Short enough for a digest's line.

func MergeHost added in v0.1.1

func MergeHost(t *planv1.Task, byID map[string]*planv1.Task) string

MergeHost is the task the merge t is shown and counted with: the first original task it serves that is part of the same azima as t (or, like t, of none); "" for any other task, or a merge that serves none there (a push or main branch correction).

func MergeMainWord

func MergeMainWord(m planv1.MergeMain) string

MergeMainWord is when Djinn merges main, as the settings say it: release, commit, off.

func MergeRunning added in v0.1.1

func MergeRunning(wish *planv1.Wish, tasks []*planv1.Task, projectID string) string

MergeRunning says, in a phrase, what merges into wish's integration branch in the project projectID now: a batch of its work being merged and tested, a correction or review worker bringing work into it, or one settling main's merge; "" when none does. While one runs, the branch does not change under it.

func MergeServes added in v0.1.1

func MergeServes(t *planv1.Task, byID map[string]*planv1.Task) []string

MergeServes are the original tasks the merge t serves, by id: the tasks it brings the work of, earlier merges among them followed back to tasks that are no merges, in order and once each. byID gives the tasks; one it lacks is left out.

func NeedsWords

func NeedsWords(needs []*planv1.ProofNeed) string

NeedsWords says what an azima's proofs need, each giver once, in the order of the enum: "a Mac, Clément's review".

func NextQuestionCode added in v0.1.1

func NextQuestionCode(ctx context.Context, r store.Reader, wishID string) (string, error)

NextQuestionCode is the code of a new question of the wish wishID: Q01, Q02… The number after the highest one its questions have or its retired codes had (Wish.retired_codes), so that a code is never given twice, deleted or moved.

func NextTaskNumber added in v0.1.1

func NextTaskNumber(ctx context.Context, r store.Reader, wishID, letter string) (string, error)

NextTaskNumber is the code of a new task of the wish wishID lettered letter, W for work and T for an azima: the number after the highest one its tasks have or its deleted tasks had (Wish.retired_codes), so that a code is never given twice, deleted or not.

func NoteEditedLine added in v0.1.2

func NoteEditedLine(q *planv1.Question) string

NoteEditedLine is the line that tells a lead the developer changed the note of their answer to q, and only it.

func Paginate added in v0.1.1

func Paginate[T any](items []T, pageSize int32, pageToken string) ([]T, string, int32, error)

Paginate slices items according to pageSize and pageToken. If pageSize <= 0, DefaultPageSize is used. If pageSize > MaxPageSize, MaxPageSize is used. If pageToken is empty, pagination starts at the beginning (offset 0). If pageToken is invalid, a connect error with CodeInvalidArgument is returned. Returns the sliced items, next_page_token (or "" if on the last page), total items count, and an error if any.

func PrincipalWish added in v0.1.1

func PrincipalWish(ctx context.Context, r store.Reader) (*planv1.Wish, error)

PrincipalWish returns the principal wish: one explicitly marked as principal by the developer (preferring an active wish if marked), or the first active wish by rank.

func ProjectNamed

func ProjectNamed(ctx context.Context, r store.Reader, name string) (*planv1.Project, error)

ProjectNamed is the project of this name, case ignored, or of this identifier.

func ProjectPushWord added in v0.1.1

func ProjectPushWord(p planv1.ProjectPush) string

ProjectPushWord is when Djinn pushes, as the settings say it: standard, on_demand.

func ProverWord

func ProverWord(p planv1.Prover, n *planv1.ProofNeed) string

ProverWord names who or what gives a proof, in the brief's words: "a Mac", "Clément's review".

func Provers

func Provers(needs string) (provers []planv1.Prover, reviewerName string)

Provers says who or what gives the proof a box needs, from the words of its needs, in the order of the enum: a Mac, a Windows machine, a review by a named person, a release, a real model, a person; something else when none of them is named. reviewer is the person whose review it needs ("Clément's review").

func PushStateOf added in v0.1.1

func PushStateOf(wish *planv1.Wish, projectID string) *planv1.WishPush

PushStateOf is the state of the push of wish in the project projectID; nil when none is recorded.

func PushStrategyWord added in v0.1.1

func PushStrategyWord(p planv1.PushStrategy) string

PushStrategyWord is how a wish integrates its work, as the settings say it: wish, azima.

func PutBlock added in v0.1.1

PutBlock adds or changes the block m names, in tx. The caller journals the command.

func QuestionWorkerOf

func QuestionWorkerOf(ctx context.Context, r store.Reader, q *planv1.Question, role planv1.TaskRole) (*planv1.Task, error)

QuestionWorkerOf is the question worker of role that still works on q (Task.role): planned, running, paused, or one Djinn resumes; nil when none does.

func QueueLeadEvent added in v0.1.1

func QueueLeadEvent(ctx context.Context, s *store.Store, e *planv1.LeadEvent, now time.Time) error

QueueLeadEvent stores e for the lead, with its id and its time: it waits there until a watch acknowledges it.

func Ranked

func Ranked(all []*planv1.Wish) []*planv1.Wish

Ranked returns the active wishes of all by rank. A wish without a rank, made before ranks, comes after the ranked ones, the oldest first.

func ReadSettings

func ReadSettings(path string) (*planv1.ProjectSettings, error)

ReadSettings reads the settings of the file at path: nil, and no error, when there is none. A file that holds something that looks like a secret is refused, comments included, without repeating it.

func ReadSettingsWithWarnings added in v0.1.1

func ReadSettingsWithWarnings(path string) (*planv1.ProjectSettings, []string, error)

ReadSettingsWithWarnings reads the settings of the file at path: nil, and no error, when there is none. A file that holds something that looks like a secret is refused, comments included, without repeating it. Any unknown fields are discarded, logged once as warnings, and returned in warnings.

func ReadTaskItemNeeds added in v0.1.1

func ReadTaskItemNeeds(line string) (box, needs string, ok bool)

ReadTaskItemNeeds parses an unchecked markdown task item ("- [ ] text (needs: ...)") and splits its box text from its needs. Returns false when the line is not an unchecked task item, is struck through, or has no needs.

func Ready

func Ready(tasks []*planv1.Task, questions []*planv1.Question) bool

Ready tells whether Djinn proposes to grant a wish that has these tasks and questions: it has tasks, every one finished (done, stopped by the user, or cut short for good), none done with problems nobody looked at (DoneWithProblems), and no question is open. A draft azima is not counted in the wish's progress: it waits to be opened. Djinn only proposes: the user grants.

func Recommended(q *planv1.Question) (planv1.Choice, bool)

Recommended is the choice a question's recommendation names, for a one-click approval. A question without options is answered yes. Otherwise the recommendation names an option by its letter first ("B: …", "**B**, because…"), or starts with the first word of one option only ("Yes: it is measured" for an option "Yes, pour it"). The window reads it the same way (recommendedChoice in src/data/format.ts).

func RefuseAzimaDependencies added in v0.1.1

func RefuseAzimaDependencies(tasks, graph []*planv1.Task) error

RefuseAzimaDependencies refuses graph, the tasks of a wish that pushes per azima as a change would leave them, when it makes an azima wait for another that it did not wait for among tasks, the wish's tasks as they are: an azima spawned or synced from its plan file with one after it, a dependency set, a task grouped into another azima. What a wish waited for before it was switched stays.

func RefuseStranding added in v0.1.1

func RefuseStranding(wish *planv1.Wish, tasks []*planv1.Task, to planv1.PushStrategy) error

RefuseStranding refuses switching wish to the push strategy to when work of it, among tasks, merged into a branch, would be left there, its further work going to another: per azima, the work of an azima merged into the wish's integration branch while the azima's own branch is another; per wish, work merged into an azima's branch other than the wish's integration branch. The work of an azima stays where it is once the azima adopts the branch it lives on (djinn task update <azima> --branch <branch>), which the refusal says. Work of no azima stays in the wish's branch.

func RefuseSwitchToAzima added in v0.1.1

func RefuseSwitchToAzima(tasks []*planv1.Task) error

RefuseSwitchToAzima refuses switching a wish to the per-azima push strategy while its azimas, among tasks, wait for each other, naming them in a line.

func ResetWarnedUnknownFields added in v0.1.1

func ResetWarnedUnknownFields()

ResetWarnedUnknownFields clears the deduplication map, for tests.

func ResolveWish added in v0.1.1

func ResolveWish(ctx context.Context, r store.Reader, name string) (*planv1.Wish, error)

ResolveWish finds a wish by identifier, rank (e.g. W1, 1), or title.

func ResolveWishPushStrategy added in v0.1.1

func ResolveWishPushStrategy(wish *planv1.Wish, settings Settings) (planv1.PushStrategy, planv1.SettingSource)

ResolveWishPushStrategy resolves the push strategy and its source for a wish, falling back to the project settings.

func RoutedLine

func RoutedLine(q *planv1.Question) string

RoutedLine is the line that tells the lead of a route question's wish where the request went: it hands it over.

func SaveDeveloperInstallQuestions added in v0.1.1

func SaveDeveloperInstallQuestions(home, projectID string, questions planv1.InstallQuestions) error

SaveDeveloperInstallQuestions writes the developer's install questions setting into their settings file in home.

func SaveDeveloperPush added in v0.1.1

func SaveDeveloperPush(home, projectID string, push planv1.ProjectPush) error

SaveDeveloperPush writes the developer's push setting into their settings file in home.

func SaveDeveloperPushStrategy added in v0.1.1

func SaveDeveloperPushStrategy(home, projectID string, strategy planv1.PushStrategy) error

SaveDeveloperPushStrategy writes the developer's push strategy setting into their settings file in home.

func SetIntegrationBranch

func SetIntegrationBranch(wish *planv1.Wish, projectID, branch string)

SetIntegrationBranch records branch as wish's integration branch in the project projectID, in place of the one it had.

func SetWatchInterval

func SetWatchInterval(d time.Duration) (restore func())

SetWatchInterval sets the least time between two messages of a Watch stream, for tests and benchmarks, and returns what puts it back.

func Slug added in v0.1.1

func Slug(s string, n int) string

Slug keeps lower-case letters and digits, joined by single dashes, at most n characters cut on a dash.

func StableBrief

func StableBrief(home string, projects []*planv1.Project) string

StableBrief is the part of a brief that changes rarely, for a wish on projects: Djinn's rules, then where each project keeps its own, and the checks Djinn runs on its work, as its settings say with Djinn's data folder home. It names the projects, never their folders.

func StartLine

func StartLine() string

StartLine is how every new lead starts, whatever its agent: from the brief, which Djinn computes from the plan.

func Status

func Status(err error) error

Status gives a Connect code to the errors of the store.

func TilasmContext

func TilasmContext(ctx context.Context, r store.Reader, home, wishID string, names []string) (string, error)

TilasmContext is what a worker's first prompt holds of the tilasms it is given (djinn task spawn --tilasm): for each, its code, title, link, what it explains, the folder of its latest version's files and the text of its page. names are codes (L01, any case) or identifiers of tilasms of the wish, repeated or separated by commas or spaces; home is Djinn's data folder. Empty for no name.

func TilasmDir

func TilasmDir(home, id string) string

TilasmDir is the folder of a tilasm in the data folder home: version n is in its folder v<n>.

func TilasmLink(id string) string

TilasmLink is the link that opens a tilasm in Djinn from anywhere: a block, a question, a terminal, a browser.

func WaitingLine added in v0.1.1

func WaitingLine(n int) string

WaitingLine is the one line Djinn types in the lead's terminal when events wait and no watch of the lead does.

func WarnUnknownField added in v0.1.1

func WarnUnknownField(path, field string) string

WarnUnknownField formats a warning for an unknown field, logs it once per file and field, and returns the warning string.

func WhenWord

func WhenWord(w planv1.CheckWhen) string

WhenWord is when a check runs, as the settings and the brief say it: commit, push.

func WishLead added in v0.1.1

func WishLead(w *planv1.Wish) *planv1.Lead

WishLead is the lead a wish kept before the one lead, nil when it kept none.

func WithAzimas

func WithAzimas(tasks []*planv1.Task) []*planv1.Task

WithAzimas is tasks with Task.azima set on their azimas, as clones: the store's own messages stay as they are.

func WithCaller added in v0.1.1

func WithCaller(ctx context.Context, caller *WorkerCaller) context.Context

WithCaller returns a context carrying the worker caller identity.

func WriteAfter

func WriteAfter(file string, codes []string) (bool, error)

WriteAfter writes what an azima depends on, by code, into its plan file's front matter, as "after: T02 T05" after its status (or last); none removes the line. It tells whether the file changed: a file that says it already is left as it is.

func WriteCode added in v0.1.1

func WriteCode(file string, code string) (bool, error)

WriteCode updates an azima's code in its plan file's front matter and title heading. It tells whether the file changed.

func WriteDescription added in v0.1.1

func WriteDescription(file string, text string) (bool, error)

WriteDescription writes the description of an azima into its plan file, after its title heading. It tells whether the file changed.

func WriteStatus added in v0.1.1

func WriteStatus(file string, status string) (bool, error)

WriteStatus writes an azima's status ("open", "draft", etc.) into its plan file's front matter. It tells whether the file changed.

func WriteTitle added in v0.1.2

func WriteTitle(file string, code string, title string) (bool, error)

WriteTitle writes an azima's title into its plan file's heading, the first "# " line after its front matter: its code and the separator after it stay ("# T07 · The orchestrator"); a file without a heading gets one, code first. It tells whether the file changed.

func WriteWish added in v0.1.1

func WriteWish(file string, wish string) (bool, error)

WriteWish sets or removes the wish of an azima in its plan file's front matter. If wish is empty, it removes any wish: line. It tells whether the file changed.

Types

type AnswerHook

type AnswerHook func(ctx context.Context, q *planv1.Question) string

AnswerHook is called with a question once its answer is stored. It says what it did with the answer, for the wish's lead: "Djinn started W12: …"; "" when the answer is the lead's to act on.

type AzimaDependency added in v0.1.1

type AzimaDependency struct {
	Azima *planv1.Task
	After []*planv1.Task
}

AzimaDependency is an azima that waits for others, itself or through the work part of it (DependencyAzimas). Under the per-azima push strategy Djinn refuses it: each azima's branch is cut from main and lands there on its own, so none holds another's work.

func AzimaDependencies added in v0.1.1

func AzimaDependencies(tasks []*planv1.Task) []AzimaDependency

AzimaDependencies lists the azimas among tasks, every task of a wish, that wait for others, in the order of their codes.

type AzimaFile

type AzimaFile struct {
	// Path is the file, as its project names it: plan/8e8d3d76-orchestrator.md.
	Path   string
	ID     string
	Code   string
	Wish   string
	Phase  string
	Status string
	Title  string
	// Description is what the file holds after its title heading: its goal and body.
	Description string
	// After is what the file says the azima depends on, by code.
	After []string
	// DoneWhen is what its Done-when sections say: their boxes, and what the unchecked ones need.
	DoneWhen DoneWhen
}

AzimaFile is what a plan file says of its azima: its front matter, between two lines "---" at the top, and its title, the first heading after it ("# T07 · The orchestrator", the code left out).

func ReadAzimaFiles

func ReadAzimaFiles(project string) ([]AzimaFile, error)

ReadAzimaFiles reads the plan files of a project's folder: plan/*.md (and plan/*/*.md) with a front matter that gives a code, and their Done-when section. A file without one (the README) is not an azima's.

func (AzimaFile) Closes

func (f AzimaFile) Closes() bool

Closes tells whether the file closes its azima: its status says done, or every box of its Done-when section is checked. A draft azima never closes.

func (AzimaFile) Done

func (f AzimaFile) Done() bool

Done tells whether the file says its azima is done.

func (AzimaFile) Draft added in v0.1.1

func (f AzimaFile) Draft() bool

Draft tells whether the file says its azima is a draft.

type Babysit added in v0.1.1

type Babysit struct {
	// Skill is the skill's name; Dir its folder.
	Skill, Dir string
	// Watch is the watcher's command line: {pr} and {mr} are the request's number, {state} a file of the watcher's
	// own under Djinn's data folder.
	Watch string
	// DoneWhen is a watcher line that ends it, done; empty: its command's exit does.
	DoneWhen string
	// Restart starts the command again after each exit, until its done line.
	Restart bool
	// Forge is the forge the declaration is for, ForgeGitHub or ForgeGitLab; empty for any.
	Forge string
}

Babysit is how a project babysits its pull or merge requests, as a skill of it declares it.

func ProjectBabysit added in v0.1.1

func ProjectBabysit(project *planv1.Project, forge string) *Babysit

ProjectBabysit is the babysit declaration of the project's own skills for forge (ForgeGitHub, ForgeGitLab): the first by name that names this forge, else the first that names none. nil without one. A summoned skill does not count: its watcher would run in the folder of the project that holds it, not in the request's repository.

func ReadBabysit added in v0.1.1

func ReadBabysit(dir string) (*Babysit, error)

ReadBabysit reads the babysit declaration of the skill in dir: nil without one, an error when it cannot be used.

func (*Babysit) Fill added in v0.1.1

func (b *Babysit) Fill(number int, state string) string

Fill is the watcher's command line for the request number, its state in the file state.

func (*Babysit) Watches added in v0.1.2

func (b *Babysit) Watches(command string, number int) bool

Watches tells whether the command line command babysits the request number: the declaration's command, {pr} and {mr} filled with number, {state} any one word, both trimmed. A watcher spawned by hand on it runs that command.

type Brief

type Brief struct {
	Stable string
	Moving string
}

Brief is where a wish stands and how to lead it, written by Djinn from the store, without a model: every lead, of any agent, starts from it. Moving is where the wish stands. Stable changes rarely: Djinn's rules and the rules of the wish's projects.

func BuildBrief

func BuildBrief(ctx context.Context, r store.Reader, home, wishID string, leads ...Leads) (Brief, error)

BuildBrief writes the brief of a wish from what r holds. home is Djinn's data folder: like the projects' folders and the home folder, it never shows. No secret: Djinn stores none, and a URL loses its credentials.

func (Brief) Text

func (b Brief) Text() string

Text is the whole brief: where the wish stands, its description first, then how to lead it.

type DoneWhen

type DoneWhen struct {
	// Found: the file has a "## Done when" section.
	Found bool
	// How many of its boxes are checked, and how many are not, nested ones included.
	Checked, Unchecked int
	// What the unchecked boxes need, box by box, when every one of them says so or holds boxes that do: nothing is
	// left for a worker. Nil while one unchecked box is work.
	Needs []*planv1.ProofNeed
}

DoneWhen is what the Done-when section of a plan file says.

func ReadDoneWhen

func ReadDoneWhen(body []byte) DoneWhen

ReadDoneWhen reads the Done-when sections of a plan file's body: each from its heading to the next heading of its level or above. A file holds several when azimas were merged into it, one in each merged part ("### Done when" under "## From T03 · …"): their boxes count together. A box goes on over the lines indented under it; a box indented under another is nested in it; a box struck through is left out.

func (DoneWhen) AllChecked

func (d DoneWhen) AllChecked() bool

AllChecked tells whether every box of the section is checked: the azima is done, whatever the status line says.

type Inbox

type Inbox struct {
	planv1connect.UnimplementedInboxServiceHandler
	// Wishes routes an item: it files it, or makes its wish and starts its watcher.
	Wishes *Wishes
}

Inbox implements InboxService, and receives what the sources print.

func (*Inbox) Receive

func (in *Inbox) Receive(ctx context.Context, src *Source, text string) (*planv1.InboxItem, error)

Receive reads a paragraph a source printed: a new item, its route proposed without a model, unless the same item came already (new, routed or dismissed) or a wish holds its link. It returns the item made, nil when none. Nothing is made nor sent: the item waits for the developer's answer.

type LeadService added in v0.1.1

type LeadService struct {
	Wishes *Wishes
}

LeadService implements planv1connect.LeadServiceHandler.

func (*LeadService) Brief added in v0.1.1

func (*LeadService) Choose added in v0.1.1

Choose answers the choice the lead's agent shows in its terminal, as its keys would: the window's answer to an approval. The lead's terminal never runs a shell (P9), so the keys go to the agent.

func (*LeadService) Get added in v0.1.1

func (*LeadService) Notes added in v0.1.2

Notes is the index of the lead's notes, or one note whole: they are built into djinn, read only.

func (*LeadService) Resume added in v0.1.1

Resume starts the lead, or attaches to it, and keeps why it could not: the window shows it until Lead is clicked again.

func (*LeadService) Set added in v0.1.1

func (*LeadService) Tell added in v0.1.1

Tell types what the developer writes in the lead's terminal, as their own words: the lead must run there, never a shell, where the text would run as a command. About a wish, the text starts by naming it.

func (*LeadService) Watch added in v0.1.1

type Leads

type Leads interface {
	// Open runs line through the user's shell in the terminal called name, in dir, or attaches to that terminal if
	// it runs; an empty line runs the shell itself, and an empty dir the home folder. It refuses to start a program
	// while a terminal of another name runs a command line that holds exclusive. It returns the command line and
	// the folder of the terminal.
	Open(name, line, dir, exclusive string) (command []string, directory string, attached bool, err error)
	// Show brings the window to the front, on the wish and the terminal.
	Show(wishID, terminal string)
	// Say types line into the running terminal called name, then Enter, once the person is not typing there. It
	// returns at once; the lines go out in order.
	Say(name, line string) error
	// SayText is Say for a text the person wrote: its line breaks stay line breaks for a program that takes a
	// paste. It tells whether the text waits for the person, typing there or before a choice on screen.
	SayText(name, text string) (waiting bool, err error)
	// Running tells whether the terminal called name runs.
	Running(name string) bool
	// Exit is how the program of the terminal called name ended, kept until a program starts there again; nil while
	// it runs, or when none ran.
	Exit(name string) *planv1.LeadExit
	// Command is the command line of the running terminal called name; nil when none runs.
	Command(name string) []string
	// Close hangs up the running terminal called name, as closing it in the window does; none runs, nothing.
	Close(name string)
	// Prompt is the choice the program of the terminal called name shows now, as read from its screen: an approval,
	// a folder to trust. Nil when it shows none, or runs nothing.
	Prompt(name string) *planv1.LeadPrompt
	// Choose picks the option index (from 0) of the choice the terminal called name shows, as its keys would. It
	// returns ErrNoChoice, typing nothing, when the screen no longer shows the choice of title, lines and options.
	Choose(name, title string, lines, options []string, index int) error
}

Leads runs the terminal of a wish's lead and shows it in the window: djinn up provides it, on its terminals and its window.

type Marks

type Marks struct {
	planv1connect.UnimplementedMarkServiceHandler
	Store *store.Store
	// Answered are called with a question once an approval has answered it.
	Answered []AnswerHook
	// Told, when set, is called next, with what they did.
	Told Told
	// Settle, when set, acts on the answer an approval gives, as Questions.Settle.
	Settle Settle
	// Approved, when set, is called with a question once the developer approved the answer the lead or a worker
	// gave it: the only approval that tells the lead something (decision Q173).
	Approved func(context.Context, *planv1.Question)
}

Marks implements MarkService. A mark lives on the question it marks, in its own list, one mark of each kind, so that it travels with it in an export. A task takes one mark, reviewed, kept the same way on the task. A block takes none: blocks are for agents, and what the developer must see is a question. Marks a block took before stay on it, and are listed no more.

type Option

type Option func(*options)

Option sets what the plan services reach beyond the store.

func WithAnswered

func WithAnswered(f AnswerHook) Option

WithAnswered calls f with a question once its answer is stored: the harness starts again the worker a yes allows to edit. With WithLeads, the wish's lead is told next (Wishes.Answered), with what f did.

func WithClock added in v0.1.1

func WithClock(now func() time.Time) Option

WithClock gives the plan services their clock; tests set a fake one.

func WithEnlightened

func WithEnlightened(f func(context.Context, *planv1.Question, string)) Option

WithEnlightened calls f with a question and the developer's note once a request to investigate it is stored: the harness starts its investigator. With WithLeads, the wish's lead is told next (Wishes.Enlightened).

func WithFillModels added in v0.1.1

func WithFillModels(f func(context.Context, []*planv1.Task)) Option

WithFillModels sets the function that fills forecast models on tasks for Watch.

func WithHome

func WithHome(home string) Option

WithHome gives the services Djinn's data folder: each developer's own settings of a project, and the tilasms' files.

func WithLanguage

func WithLanguage(language string) Option

WithLanguage writes the texts Djinn puts in the plan for the developer, such as the question that routes a request, in language; English by default.

func WithLeadBroadcaster added in v0.1.1

func WithLeadBroadcaster(b *func()) Option

WithLeadBroadcaster gives the caller what tells the open Watch streams that the choice the lead shows in its terminal came, changed or went (Wishes.ChangeLead).

func WithLeadFailed added in v0.1.1

func WithLeadFailed(err error) Option

WithLeadFailed gives LeadService.Get why the lead could not start before the services ran, as djinn up resumes it: the window shows it beside Lead until Lead starts it.

func WithLeads

func WithLeads(l Leads) Option

WithLeads gives the wishes the terminals of their leads, for WishService.Resume.

func WithLoad added in v0.1.1

func WithLoad(load func() djinnv1.LoadNotch) Option

WithLoad gives the wishes Djinn's current load notch, for WishService.Watch.

func WithLoadBroadcaster added in v0.1.1

func WithLoadBroadcaster(b *func(djinnv1.LoadNotch)) Option

WithLoadBroadcaster gives the caller what notifies the open Watch streams of a load notch change.

func WithPages

func WithPages(p *Pages) Option

WithPages gives the wishes their pages, for WishService.Render and Sync.

func WithPusher added in v0.1.1

func WithPusher(p Pusher) Option

WithPusher gives ProjectService the pusher for pushing and computing sync status.

func WithShowTilasm

func WithShowTilasm(show func(wishID, tilasmID string) bool) Option

WithShowTilasm gives TilasmService.Open the window: show shows a tilasm in its wish's Tilasms tab, and tells whether a native window came to the front.

func WithTilasmURL

func WithTilasmURL(url func(id string) string) Option

WithTilasmURL gives TilasmService.Get the local http address of a tilasm's files, by its identifier; empty while Djinn serves no http.

func WithWatchers

func WithWatchers(spawn SpawnWatcher) Option

WithWatchers lets a wish made from a template start its watcher.

func WithWorkers

func WithWorkers(w WishWorkers) Option

WithWorkers gives the wishes their workers: a paused wish stops them (Wishes.Workers).

type Pages

type Pages struct {

	// Home is the data directory, left out of the pages, which hold the synced ones.
	Home string
	// Version of Djinn, shown on the pages.
	Version string
	// Language of the pages' own texts.
	Language string
	// Interval is the least time between two renders of the synced pages: pageInterval by default.
	Interval time.Duration
	// contains filtered or unexported fields
}

Pages renders the pages of wishes, and keeps the synced ones up to date: every committed change of a synced wish renders its page again, at most once an Interval. A page is synced while its file exists: djinn up takes back the pages it finds when it starts, and deleting a file stops it.

func NewPages

func NewPages(s *store.Store, home, version string) *Pages

NewPages returns the pages of the wishes in s, and starts listening to its changes. Run keeps them up to date.

func (*Pages) File

func (p *Pages) File(wishID string) string

File is where the synced page of a wish is.

func (*Pages) Page

func (p *Pages) Page(ctx context.Context, wishID string) ([]byte, error)

Page renders the page of a wish, without secret nor local path.

func (*Pages) Run

func (p *Pages) Run(ctx context.Context)

Run keeps the synced pages up to date until ctx ends. It first takes back the pages of the data directory, and renders them again.

func (*Pages) Sync

func (p *Pages) Sync(ctx context.Context, wishID string) (string, error)

Sync renders the page of a wish in its file, and keeps it up to date from now on.

type Projects

type Projects struct {
	planv1connect.UnimplementedProjectServiceHandler
	Store *store.Store
	// Home is Djinn's data folder, which holds the developer's own settings of each project; empty: none are read.
	Home   string
	Pusher Pusher
}

Projects implements ProjectService.

func (*Projects) Allow added in v0.1.2

Allow shows the watcher commands the developer allows in a project for themselves, or allows one, or takes one back: in their own settings file, never in the repository.

func (*Projects) Branches added in v0.1.1

Branches lists the local branches of a project's repository, the latest commit first, without the branches of Djinn's tasks: where a wish's work may land.

type Pusher added in v0.1.1

type Pusher interface {
	Push(ctx context.Context, wishID, projectID, branch string) (*planv1.IntegrationPush, error)
	Syncs(ctx context.Context, project *planv1.Project) ([]*planv1.ProjectSync, error)
}

Pusher pushes a wish's branches, all or only one, and computes how far each branch it pushes in a project is out of sync with its remote.

type Questions

type Questions struct {
	planv1connect.UnimplementedQuestionServiceHandler
	Store *store.Store
	// Answered are called with a question once its answer is stored.
	Answered []AnswerHook
	// Told, when set, is called next, with what they did.
	Told Told
	// NoteEdited, when set, is called with a question whose answer kept its choice and changed its note only, with
	// the note it had: the hooks do not run again, the lead hears of the note.
	NoteEdited func(ctx context.Context, q *planv1.Question, was string)
	// Enlightened are called with a question once a request to investigate it is stored, with its note.
	Enlightened []func(ctx context.Context, q *planv1.Question, note string)
	// Settle, when set, acts on an answer in the transaction that stores it, and returns what follows once it is
	// stored, if anything: a question that routes a request files it, or makes its wish.
	Settle Settle
	// Workers tells whether a task is running.
	Workers WishWorkers
}

Questions implements QuestionService.

func (*Questions) Enlighten

Enlighten records a request to investigate an open question, with what to dig into.

func (*Questions) Move added in v0.1.1

Move moves an open question to another wish, optionally along with tasks that name it as their decision.

func (*Questions) Revise

Revise changes an open question after investigating: what is given replaces the question's own, which the round keeps.

func (*Questions) Withdraw added in v0.1.1

Withdraw closes an open question without an answer.

type Settings

type Settings struct {
	Provider     planv1.Provider
	Model        string
	MaxBudgetUSD float64
	Branch       string // a template: {code}, {slug}, {uuid8}
	// How Djinn integrates the project's finished work (T07): the generated files as globs, the command that makes
	// them, the one that makes a fresh worktree ready, and the one that installs its new build; empty when not set.
	Generated                []string
	Generate, Setup, Install string
	TestOne                  string
	// The checks Djinn runs before it commits a task's work and before it pushes, in the order the file names them.
	Checks []*planv1.ProjectCheck
	// How many correction workers Djinn starts for a batch that conflicts in code or tests red, before it asks.
	CorrectionAttempts int

	// EnlightenWorkers says whether Djinn starts an investigator after a request to investigate ("Enlighten me").
	EnlightenWorkers  bool
	QuestionProvider  planv1.Provider
	QuestionModel     string
	QuestionBudgetUSD float64

	// How Djinn keeps each wish's integration branch up with the project's main branch: the branch ("" for the
	// remote's default), when it merges it, how often it fetches it at most; and whether a release of Djinn installs by
	// itself while the person's checkout is on main.
	MainBranch       string
	MergeMain        planv1.MergeMain
	MergeMainEvery   time.Duration
	InstallReleases  bool
	Push             planv1.ProjectPush
	PushStrategy     planv1.PushStrategy
	InstallQuestions planv1.InstallQuestions
	// Babysit says whether Djinn babysits the pull or merge request a task opens, with the project's babysit skill.
	Babysit bool
	// WatchCommands are the commands, or their starts, the developer lets a watcher run in the project besides those
	// its .agents/permissions.txtpb lists: from their own file only.
	WatchCommands []string
	// InstallBuilds says whether a build of the running Djinn's line, once pushed, installs by itself (W554).
	InstallBuilds bool
	Warnings      []string

	ProviderFrom, ModelFrom, BudgetFrom, BranchFrom, GeneratedFrom, GenerateFrom, SetupFrom            planv1.SettingSource
	ChecksFrom, AttemptsFrom, InstallFrom, TestOneFrom                                                 planv1.SettingSource
	EnlightenWorkersFrom                                                                               planv1.SettingSource
	QuestionProviderFrom, QuestionModelFrom, QuestionBudgetFrom                                        planv1.SettingSource
	MainBranchFrom, MergeMainFrom, MergeMainEveryFrom, InstallReleasesFrom, PushFrom, PushStrategyFrom planv1.SettingSource
	InstallQuestionsFrom, BabysitFrom, WatchCommandsFrom, InstallBuildsFrom                            planv1.SettingSource
}

Settings are a project's settings as its workers get them, each with where it comes from.

func LoadSettings

func LoadSettings(home string, project *planv1.Project) (Settings, error)

LoadSettings reads the settings of project (nil outside any project): its repository's, then the developer's in Djinn's data folder home. A file that cannot be read is an error that names it.

func ResolveSettings

func ResolveSettings(repo, dev *planv1.ProjectSettings) Settings

ResolveSettings merges the repository's settings and the developer's, either nil when there is none. The developer's win, setting by setting; a file that sets the provider sets the model with it, so that a model never goes to a provider it is not one of.

func (Settings) ChecksAt

func (s Settings) ChecksAt(when planv1.CheckWhen) []*planv1.ProjectCheck

ChecksAt are the checks Djinn runs at when: before a commit, or before a push.

func (Settings) ChecksBrief

func (s Settings) ChecksBrief() string

ChecksBrief says, in a sentence or two, which checks Djinn runs on the project's work and when, how a worker runs the commit checks and targeted tests (never push checks), and what a fresh worktree needs first; "" for a project that sets none. The lead's brief and each worker's first prompt carry it.

func (Settings) CommitGates

func (s Settings) CommitGates() string

CommitGates lists how an agent runs the commit checks, each through its gate: "`djinn gate run lint -- make lint`".

func (Settings) Integrates

func (s Settings) Integrates() bool

Integrates tells whether Djinn integrates the project's finished work by itself: once a check is set.

func (Settings) Rows

func (s Settings) Rows() []*planv1.ProjectSetting

Rows are the settings as djinn project show lists them.

type Settle

type Settle func(ctx context.Context, tx *store.Tx, q *planv1.Question) (func(context.Context), error)

Settle acts on the answer of q in tx, the transaction that stores it, and may change q before it is stored. It returns what follows once the answer is stored, if anything.

type SkillDir

type SkillDir struct {
	// Name is its folder's name.
	Name string
	// Dir is its folder, absolute.
	Dir string
	// Description is what it does, from its SKILL.md.
	Description string
}

SkillDir is a skill found on this machine.

func FindSkill

func FindSkill(dir, name string) (SkillDir, error)

FindSkill is the skill name of the project folder dir, case ignored.

func ProjectSkills

func ProjectSkills(dir string) []SkillDir

ProjectSkills are the skills held in the project folder dir, by name; none when dir is empty or has none.

type Source

type Source struct {
	// Skill is the skill's name; Dir its folder.
	Skill, Dir string
	// HolderID is the project that holds the skill, Holder its name: the source is named <Holder>/<Skill>.
	HolderID, Holder string
	// ProjectID is the project that holds the skill or summons it: the command runs in its folder.
	ProjectID string
	// Watch is the command line, run without a shell.
	Watch string
	// Every is the least time between two starts of the command.
	Every time.Duration
	// Plugged tells whether the source is plugged in on this machine: only then does its command run.
	Plugged bool
	// Err says why the source cannot be used; nil when it can.
	Err error
}

Source is the inbox source of a skill, read from its SKILL.md.

func ReadSource

func ReadSource(dir string) (*Source, error)

ReadSource reads the inbox source of the skill in dir: nil without one, an error when it cannot be used.

func Sources

func Sources(ctx context.Context, r store.Reader, projects []*planv1.Project) ([]*Source, error)

Sources are the inbox sources plugged in on this machine that can run, from the skills the projects use, in the projects' order then by name. A skill used by several projects runs once, in the first one's folder. A source that cannot be used is left out: djinn inbox sources says why. One not plugged in never runs.

func (*Source) Name

func (s *Source) Name() string

Name is the source as the developer names it: <project>/<skill>, the project that holds the skill.

type SpawnWatcher

type SpawnWatcher func(ctx context.Context, wishID, projectID, title, watch string, restart bool) (code string, err error)

SpawnWatcher starts the watcher task of a wish, in the project projectID, on the command line watch, and gives its code. djinn up gives the harness's (harness.SpawnWatcher).

type Summoned

type Summoned struct {
	SkillDir
	// Source is <project>/<skill>.
	Source string
	// ProjectID is the project that holds it.
	ProjectID string
	// Missing says why the skill cannot be found; empty when it is.
	Missing string
}

Summoned is a skill a project summons, resolved on this machine: Missing says why it is not found.

func SummonedSkills

func SummonedSkills(ctx context.Context, r store.Reader, project *planv1.Project) ([]Summoned, error)

SummonedSkills are the skills project summons, each found in its source project or said missing.

type Template

type Template struct {
	// Skill is the skill's name; Dir its folder.
	Skill, Dir string
	// ProjectID is the project that holds the skill or summons it: the watcher runs in its folder.
	ProjectID string
	// Title is the new wish's title, Watch the watcher's command line, both with placeholders: {name} is the group
	// name of Match. DoneWhen is a watcher line that means done.
	Title, Watch, DoneWhen string
	// Restart starts the watcher's command again after each exit, until its done line.
	Restart bool
	// Match picks the template for a request, and fills the placeholders with its named groups.
	Match *regexp.Regexp
}

Template is the wish template of a skill, read from its SKILL.md.

func ReadTemplate

func ReadTemplate(dir string) (*Template, error)

ReadTemplate reads the wish template of the skill in dir: nil without one, an error when it cannot be used.

func Templates

func Templates(ctx context.Context, r store.Reader, projects []*planv1.Project) ([]*Template, error)

Templates are the wish templates of the skills the projects use, their own then those they summon, in the projects' order then by name. A template that cannot be used is left out.

func (*Template) Builds added in v0.1.2

func (t *Template) Builds(command string) bool

Builds tells whether command is a command line Fill makes from the template: its watch, each placeholder filled with one word as quoteWord writes it, both trimmed. A command that merely starts the same way, or holds another word, is not.

func (*Template) Fill

func (t *Template) Fill(request string) (title, watch string, ok bool)

Fill fills the template for request: the title, and the watcher's command line, each value one word of it. False when the request does not match.

type Tilasms

type Tilasms struct {
	planv1connect.UnimplementedTilasmServiceHandler
	Store *store.Store
	// Home is Djinn's data folder: the tilasms' files are in its folder tilasms. Empty: the service is unavailable.
	Home string
	// MaxBytes is the ceiling of a new tilasm, in bytes; 0: DefaultTilasmBytes.
	MaxBytes int64
	// Show shows a tilasm in the window, in its wish's Tilasms tab, and tells whether a native window came to the
	// front. Nil: Open is unavailable.
	Show func(wishID, tilasmID string) bool
	// URL is the local http address of a tilasm's latest version, by its identifier; empty, or nil, while Djinn serves
	// no http.
	URL func(id string) string
}

Tilasms implements TilasmService.

func (*Tilasms) Files

func (t *Tilasms) Files() http.Handler

Files serves the latest version of each tilasm at server.TilasmPrefix: /tilasm/<id>/ is its index.html, and its other files are under it, by their paths. Every answer carries tilasmPolicy. A folder serves its index.html, never a listing.

func (*Tilasms) PutData

PutData puts the files the window read: they are written to a temporary folder of the tilasms' folder, then put as a folder, or as a .zip, or imported when the .zip is a tilasm's export. The journal keeps the request without the files' contents, as a wish's import does.

type Told

type Told func(ctx context.Context, q *planv1.Question, was *planv1.Answer, did string)

Told tells the wish's lead that q was answered, did saying what the hooks did with the answer; was is the answer it replaced, when the developer changed their choice, or nil.

type WishWorkers

type WishWorkers interface {
	Shelve(ctx context.Context, wishID string)
	Wake()
	// StopWish stops the wish's workers for good, and waits until they have ended.
	StopWish(ctx context.Context, wishID string) error
	HasRun(taskID string) bool
}

WishWorkers reaches the workers of the wishes: djinn up gives the harness's. A paused wish's workers stop, and wait to resume with it; a wish active again wakes the scheduler, which starts them.

type Wishes

type Wishes struct {
	planv1connect.UnimplementedWishServiceHandler
	Store *store.Store
	// Leads runs the leads' terminals; nil where djinn up does not serve them, and Resume is then unavailable.
	Leads Leads
	// Pages renders the wishes' pages and keeps the synced ones up to date; nil where djinn up does not run them,
	// and Sync is then unavailable.
	Pages *Pages
	// Language of the texts Djinn writes in the plan for the developer; English when empty.
	Language string
	// Watchers starts the watcher of a wish made from a template; nil where djinn up does not run tasks, and the
	// lead is then told to start it.
	Watchers SpawnWatcher
	// Workers stops the workers of a paused wish, and wakes the scheduler for an active one; nil where djinn up does
	// not run tasks.
	Workers WishWorkers
	// Home is Djinn's data folder, which holds the tilasms' files; empty: a wish with tilasms neither exports nor
	// imports.
	Home string
	// Load reports Djinn's current load notch; nil where djinn up does not run machine monitoring.
	Load func() djinnv1.LoadNotch
	// FillModels fills forecast models on tasks for Watch.
	FillModels func(context.Context, []*planv1.Task)
	// Clock gives the wishes their time; nil uses time.Now.
	Clock func() time.Time
	// contains filtered or unexported fields
}

Wishes implements WishService.

func (*Wishes) Activate

Activate makes a paused or granted wish active again, last by rank. Three wishes being active, it takes the third place, and the third wish is paused: only the three first wishes are active.

func (*Wishes) Allow

Allow gives the wish's workers a right in one of its projects, or takes it back with ALLOWANCE_NONE.

func (*Wishes) Answered

func (w *Wishes) Answered(ctx context.Context, q *planv1.Question, was *planv1.Answer, did string)

Answered tells the lead that the developer answered q, in one line, with what Djinn did with the answer (did) when it settled it: an event in the lead's queue, which its watch hands out (decision Q191), never lost. Handlers calls it once the answer is stored, when it serves the leads; the answer stays in the brief whatever happens here. While no lead runs, the question is marked waiting for a lead, until the lead acknowledges it. was is the answer it replaced, when the developer changed their choice: the line says so. One answer is one event: the answer events of q that still wait for the lead give way to this one.

func (*Wishes) Approved added in v0.1.1

func (w *Wishes) Approved(ctx context.Context, q *planv1.Question)

Approved tells the lead that the developer approved the answer the lead or a worker gave q: the decision is the developer's now. Marks calls it once the approval is stored, and only for such an answer (decision Q173).

func (*Wishes) Brief

Brief writes the brief of a wish.

func (*Wishes) ChangeLead added in v0.1.1

func (w *Wishes) ChangeLead()

ChangeLead tells the open Watch streams that the lead changed outside the store: the choice its agent shows in its terminal came, changed or went. The window reads the lead again (LeadService.Get), as for a lead stored.

func (*Wishes) ChangeLoad added in v0.1.1

func (w *Wishes) ChangeLoad(notch djinnv1.LoadNotch)

ChangeLoad tells the open Watch streams that Djinn's load notch changed.

func (*Wishes) Delete

Delete deletes a wish and everything that belongs to it: its tasks and their events, its questions, its blocks. Its workers stop first: an active wish is paused, which the journal records, so that no task of it starts again. Once it is gone, each task's worktree that holds no work is removed (cleanWorktree); the others stay, the response says why. Every branch stays. An inbox item routed to it forgets it.

func (*Wishes) Describe

Describe sets the wish's description, in place of what it had; empty takes it back to the title.

func (*Wishes) Enlightened

func (w *Wishes) Enlightened(ctx context.Context, q *planv1.Question, note string)

Enlightened tells the lead of q's wish that the developer wants to know more before answering q, with their note.

func (*Wishes) Export

Export writes the wish to a file.

func (*Wishes) Grant

Grant grants a wish: the user says it is done. Djinn proposes it when the wish is ready, and never grants it itself; the user may grant it at any time.

func (*Wishes) Import

Import reads a wish from a file.

func (*Wishes) ImportData

ImportData reads a wish from the content of a file.

func (*Wishes) Move

Move gives a wish another rank, and shifts the others. A wish that is not active becomes active at that rank, the third at most; the wish it pushes past the third place is paused.

func (*Wishes) NoteEdited added in v0.1.2

func (w *Wishes) NoteEdited(ctx context.Context, q *planv1.Question, was string)

NoteEdited tells the lead that the developer changed the note of their answer to q, which had the note was: the answer event of q that still waits for the lead takes the new note in its place; or else one event says it, which the next edits change in turn while it waits. However many times the note is saved, the lead reads it once.

func (*Wishes) Notify added in v0.1.1

func (w *Wishes) Notify(ctx context.Context, e *planv1.LeadEvent) error

Notify queues e for the lead, and wakes its watch. With none waiting, Djinn types one short line in the lead's terminal once the events settle: "Djinn: N events waiting, run djinn lead watch".

func (*Wishes) Pause

Pause sets an active wish aside: it keeps everything, its workers stop until it is active again, and it leaves its place to another one.

func (*Wishes) Principal added in v0.1.1

Principal sets or reports whether a wish is the principal wish.

func (*Wishes) PushStrategy added in v0.1.1

PushStrategy shows or sets the push strategy of a wish.

func (*Wishes) RemindLead added in v0.1.1

func (w *Wishes) RemindLead()

RemindLead types the line that says events wait, after a grace for the lead's watch to come back, when events wait and no watch does: djinn up calls it once it runs, so that a lead whose watch died with the last djinn up hears of what happened meanwhile, the restart first.

func (*Wishes) Rename added in v0.1.1

Rename sets the wish's title, in place of what it had.

func (*Wishes) Render

Render writes the page of a wish to a file.

func (*Wishes) Route

Route proposes where a request goes; with ask, it asks it as a question on the wish the request came to.

func (*Wishes) Snapshot

Snapshot returns everything the wish holds, with the identifiers and folders of this machine.

func (*Wishes) Sync

Sync renders the page of a wish in the data directory, and keeps it up to date while djinn up runs.

func (*Wishes) Tell

func (w *Wishes) Tell(ctx context.Context, wishID, line string) error

Tell types line in the terminal of the lead, then Enter, once the person is not typing there: the lead reads it as a message, and acts. A lead that does not run is reopened first, on its session, as Resume does, without bringing the window to the front. ErrNoLead when there is none to tell.

func (*Wishes) Watch

Watch follows the changes of the wishes: a first message that names everything, then the changes, coalesced, with the tasks, questions and blocks that changed.

func (*Wishes) Watched

func (w *Wishes) Watched(ctx context.Context, task *planv1.Task, text string) (done bool, err error)

Watched reads a paragraph the watcher task printed, and says whether it holds the done line of its wish's template: Djinn then asks the developer whether to grant the wish, once while the question is open. It never grants the wish itself. A wish granted already, or without a template, is left as it is.

type WorkerCaller added in v0.1.1

type WorkerCaller struct {
	TaskID string
	WishID string
}

WorkerCaller identifies a worker making a request through its task and wish.

func CallerFromContext added in v0.1.1

func CallerFromContext(ctx context.Context) *WorkerCaller

CallerFromContext returns the worker caller from ctx, or nil if none.

Jump to

Keyboard shortcuts

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