go

module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0

README

Go IR core

Primary SDK for Phase 1B (epic #113). Full Trajectory IR stack under trajir/. Python remains the supported reference and parity port from Phase 1A.

Packages

Path Role
trajir/nodes Node kinds, RFC 8785 payload hash, node id
trajir/log SQLite append only NodeLog
trajir/postgres PostgreSQL NodeLog (parity with drivers.postgres; needs DSN)
trajir/effects Effect classes and fail closed MCP mapping
trajir/durable Pluggable step memoization backend
trajir/durable/temporal Temporal Backend + worker registration
trajir/resume Block and gate, and RunStep seal path for one agent step
trajir/client Thin SDK: open, project, seal, exec, commit, resume, RunStep
trajir/cas Filesystem CAS and S3 compatible CAS (sharded layout; thin rehydrate; AWS SDK v2 via NewS3StoreFromEnv)
trajir/tir Portable .tir package export / import (thin and fat)
trajir/mcp Model Context Protocol server tools (status, export/import, verify)
cmd/trajir-mcp stdio MCP binary for Claude Code / Cursor style hosts
trajir/projector Default context projector (R04; size metric = RFC 8785 / JCS bytes)

Integrations contract: docs/INTEGRATIONS.md.

Durable backend decision (issues #16 and #24)

Coding default LocalSQLite (file) and Memory (tests) in trajir/durable
Production target Temporal (trajir/durable/temporal). Restate welcome later.
Why Matches master README's durable-backend principle (§3.1): never hand roll crash/retry/lease logic, consume an external engine instead. Temporal is the master spec's recognized production backend for Go (§3.1, §5, §12.0); DBOS remains the Python default. Local memo stays the default for contributors; Temporal persists step memos when a cluster and worker are available.

Model inference and tools must go through durable.Step / Infer / Tool. Block and gate still relies on the NodeLog for NON_IDEMPOTENT_WRITE.

Temporal (optional)

Env (defaults match local Temporal dev server):

Variable Default
TEMPORAL_HOSTPORT localhost:7233
TEMPORAL_NAMESPACE default
TEMPORAL_TASK_QUEUE trajectory-ir

Run a worker process that calls temporal.NewWorker and Run. Use temporal.Dial or temporal.NewBackend as a durable.Backend with durable.Infer / durable.Tool / resume.RunStep.

Default go test ./... does not need Temporal. Optional live check:

# with Temporal listening on localhost:7233 and a worker on trajectory-ir
go test -tags=temporal_integration ./trajir/durable/temporal -count=1 -v

Client usage

tr, err := client.OpenTrajectory("demo", "t1", client.Options{WorkDir: dir})
// ...
results, err := tr.RunStep(ctx, 1, model, tools, map[string]any{"k": "v"})
// reopen same workdir
tr2, err := client.Resume("demo", "t1", client.Options{WorkDir: dir})

Demo: kill mid deploy

Human runnable story (seal, kill, resume):

cd go
go run ./examples/kill_mid_deploy -workdir ./kill_mid_deploy-data -crash-during=tool_call
# kill when deploy starts, then:
go run ./examples/kill_mid_deploy -workdir ./kill_mid_deploy-data -resume

See examples/kill_mid_deploy/README.md.

Go Python
OpenTrajectory open_trajectory
Resume resume
Project project
SealDecision seal_decision
ExecTool exec_tool
CommitStep commit_step
RunStep full step via runtime (convenience)

Portable packages (.tir)

Matches the Python reference in pkg/trajectory_ir/package/tir.py (README §9).

import (
    nodelog "github.com/Coder-s-OG-s/Trajectory-IR/go/trajir/log"
    "github.com/Coder-s-OG-s/Trajectory-IR/go/trajir/tir"
)

// Export thin package
path, err := tir.Export(nl, "t-export", "out.tir", tir.ExportOptions{Mode: tir.ModeThin})

// Import (always verifies node ids; idempotent append)
pkg, err := tir.Import(path, nl)

// Load without writing to a log
pkg, err = tir.Load(path)
Go Python
tir.Export export_tir
tir.Import import_tir
tir.Load load_tir
tir.LoadUnverified load_tir_unverified (both gated behind TRAJIR_ALLOW_UNVERIFIED=1)

Fat mode uses the same CAS layout: artifacts/cas/<2-char-shard>/<sha256>. Optional package signatures: tir.Sign / tir.Verify and Export SignKey (trajir-pkg-sig-v1). Unsigned remains the default. Redacted export is Python-only for now.

Cross-language fixtures: testdata/sample_thin.tir and testdata/sample_signed.tir (regenerate with python scripts/gen_tir_fixture.py).

Test

cd go
go test ./...

Crash resume conformance (R01/R02 style) lives under conformance/. Package signatures: R09–R11.

  1. In-process tests always run (panic after seal, TOOL_CALL pre-seed for gate).
  2. Subprocess tests build cmd/crashagent, hard-kill at markers, then resume. They skip if the host blocks running the binary (some Windows policies).
cd go
go test ./conformance -count=1 -v

Directories

Path Synopsis
cmd
crashagent command
Command crashagent is a fixture for R01/R02 style crash resume tests.
Command crashagent is a fixture for R01/R02 style crash resume tests.
trajir-mcp command
Command trajir-mcp is the Trajectory IR Model Context Protocol server (stdio).
Command trajir-mcp is the Trajectory IR Model Context Protocol server (stdio).
examples
adoption_host command
Package main is the Go adoption host demo (public client APIs only).
Package main is the Go adoption host demo (public client APIs only).
kill_mid_deploy command
Command kill_mid_deploy is the human runnable Go demo for honest seal resume.
Command kill_mid_deploy is the human runnable Go demo for honest seal resume.
trajir
cas
Package cas implements content addressed artifact storage for the local profile (README section 11.2).
Package cas implements content addressed artifact storage for the local profile (README section 11.2).
client
Package client is a thin Go surface over Trajectory IR primitives.
Package client is a thin Go surface over Trajectory IR primitives.
durable
Package durable is the Go pluggable execution backend for Trajectory IR.
Package durable is the Go pluggable execution backend for Trajectory IR.
effects
Package effects ports Trajectory IR tool effect classes and MCP mapping.
Package effects ports Trajectory IR tool effect classes and MCP mapping.
graft
Package graft transfers artifact refs between trajectories (R07).
Package graft transfers artifact refs between trajectories (R07).
log
Package nodelog provides an append only, content addressed node log on SQLite.
Package nodelog provides an append only, content addressed node log on SQLite.
mcp
Package mcp implements a Model Context Protocol server for Trajectory IR.
Package mcp implements a Model Context Protocol server for Trajectory IR.
nodes
Package nodes implements Trajectory IR node identity for the Go IR core.
Package nodes implements Trajectory IR node identity for the Go IR core.
postgres
Package postgres provides a PostgreSQL backed NodeLog matching SQLite semantics.
Package postgres provides a PostgreSQL backed NodeLog matching SQLite semantics.
projector
Package projector implements the default context projector (R04).
Package projector implements the default context projector (R04).
redact
Package redact implements shared secret/thought scrubbing for export and projection (R08).
Package redact implements shared secret/thought scrubbing for export and projection (R08).
resume
Package resume holds Go seal and resume helpers: block and gate, and RunStep.
Package resume holds Go seal and resume helpers: block and gate, and RunStep.
sandbox
Package sandbox implements live vs sandbox run modes (R06).
Package sandbox implements live vs sandbox run modes (R06).
tir
Package signature support for .tir (README §9.1, trajir-pkg-sig-v1).
Package signature support for .tir (README §9.1, trajir-pkg-sig-v1).
workdir
Package workdir provides generic, confinement-policy-free filesystem helpers for resolving user-supplied paths safely: canonicalizing directories, walking up to the nearest existing ancestor before resolving symlinks (so a symlinked parent can't be combined with a nonexistent leaf path to land somewhere unexpected), checking subpath containment, and rejecting symlinked leaf files.
Package workdir provides generic, confinement-policy-free filesystem helpers for resolving user-supplied paths safely: canonicalizing directories, walking up to the nearest existing ancestor before resolving symlinks (so a symlinked parent can't be combined with a nonexistent leaf path to land somewhere unexpected), checking subpath containment, and rejecting symlinked leaf files.

Jump to

Keyboard shortcuts

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