@aitoroses/telar 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +457 -3
  2. package/dist/compile.d.ts +48 -0
  3. package/dist/compile.js +1240 -0
  4. package/dist/contract.d.ts +109 -0
  5. package/dist/contract.js +491 -0
  6. package/dist/evaluator.d.ts +23 -0
  7. package/dist/evaluator.js +40 -0
  8. package/dist/evidence.d.ts +23 -0
  9. package/dist/evidence.js +74 -0
  10. package/dist/guide.d.ts +8 -0
  11. package/dist/guide.js +16 -0
  12. package/dist/install.d.ts +104 -0
  13. package/dist/install.js +402 -0
  14. package/dist/iso.d.ts +10 -0
  15. package/dist/iso.js +73 -0
  16. package/dist/node/build.d.ts +2 -0
  17. package/dist/node/build.js +56 -0
  18. package/dist/node/telar-module.d.ts +2 -0
  19. package/dist/node/telar-module.js +28 -0
  20. package/dist/observer.d.ts +38 -0
  21. package/dist/observer.js +53 -0
  22. package/dist/pieces.d.ts +230 -0
  23. package/dist/pieces.js +178 -0
  24. package/dist/powers.d.ts +46 -0
  25. package/dist/powers.js +126 -0
  26. package/dist/protocol.d.ts +220 -0
  27. package/dist/protocol.js +243 -0
  28. package/dist/query.d.ts +67 -0
  29. package/dist/query.js +102 -0
  30. package/dist/read.d.ts +37 -0
  31. package/dist/read.js +27 -0
  32. package/dist/runner.d.ts +113 -0
  33. package/dist/runner.js +134 -0
  34. package/dist/scenario/builder.d.ts +25 -0
  35. package/dist/scenario/builder.js +603 -0
  36. package/dist/scenario/templates.d.ts +35 -0
  37. package/dist/scenario/templates.js +64 -0
  38. package/dist/scenario/types.d.ts +432 -0
  39. package/dist/scenario/types.js +10 -0
  40. package/dist/scenario/validate.d.ts +7 -0
  41. package/dist/scenario/validate.js +19 -0
  42. package/dist/scenario.d.ts +4 -0
  43. package/dist/scenario.js +4 -0
  44. package/dist/schema.d.ts +221 -0
  45. package/dist/schema.js +227 -0
  46. package/dist/seating.d.ts +47 -0
  47. package/dist/seating.js +26 -0
  48. package/dist/send-hook.d.ts +46 -0
  49. package/dist/send-hook.js +123 -0
  50. package/dist/show.d.ts +34 -0
  51. package/dist/show.js +1 -0
  52. package/dist/source.d.ts +85 -0
  53. package/dist/source.js +104 -0
  54. package/dist/spec.d.ts +21 -0
  55. package/dist/spec.js +18 -0
  56. package/dist/standard-schema.d.ts +21 -0
  57. package/dist/standard-schema.js +1 -0
  58. package/dist/std/accuracy.d.ts +12 -0
  59. package/dist/std/accuracy.js +122 -0
  60. package/dist/std/ack.d.ts +14 -0
  61. package/dist/std/ack.js +43 -0
  62. package/dist/std/actions.d.ts +105 -0
  63. package/dist/std/actions.js +153 -0
  64. package/dist/std/brief.d.ts +36 -0
  65. package/dist/std/brief.js +78 -0
  66. package/dist/std/claude-code.d.ts +9 -0
  67. package/dist/std/claude-code.js +113 -0
  68. package/dist/std/compare.d.ts +29 -0
  69. package/dist/std/compare.js +36 -0
  70. package/dist/std/git-workspace.d.ts +44 -0
  71. package/dist/std/git-workspace.js +184 -0
  72. package/dist/std/judgment.d.ts +85 -0
  73. package/dist/std/judgment.js +462 -0
  74. package/dist/std/observe-command.d.ts +23 -0
  75. package/dist/std/observe-command.js +151 -0
  76. package/dist/std/observe-github-checks.d.ts +24 -0
  77. package/dist/std/observe-github-checks.js +289 -0
  78. package/dist/std/observe-http-status.d.ts +27 -0
  79. package/dist/std/observe-http-status.js +193 -0
  80. package/dist/std/plan.d.ts +7 -0
  81. package/dist/std/plan.js +28 -0
  82. package/dist/std/queries.d.ts +31 -0
  83. package/dist/std/queries.js +318 -0
  84. package/dist/std/reading.d.ts +17 -0
  85. package/dist/std/reading.js +88 -0
  86. package/dist/std/schedule.d.ts +19 -0
  87. package/dist/std/schedule.js +122 -0
  88. package/dist/std.d.ts +15 -0
  89. package/dist/std.js +15 -0
  90. package/dist/types.d.ts +370 -0
  91. package/dist/types.js +1 -0
  92. package/dist/values.d.ts +81 -0
  93. package/dist/values.js +129 -0
  94. package/package.json +62 -5
@@ -0,0 +1,105 @@
1
+ import { type Action, type RunnableAction } from "../pieces.js";
2
+ import { type Contract, type FieldSchemaMap, type OptionalType, type StructContract, type TypeDef } from "../schema.js";
3
+ type Str = TypeDef<string>;
4
+ type Int = TypeDef<number>;
5
+ type Opt<T> = OptionalType<TypeDef<T>>;
6
+ type In<F extends FieldSchemaMap> = StructContract<string, F>;
7
+ type ProcessIn = {
8
+ readonly executable: Str;
9
+ readonly args: Opt<readonly string[]>;
10
+ readonly cwd: Opt<string>;
11
+ };
12
+ type ProcessOut = {
13
+ readonly exitCode: Int;
14
+ readonly stdout: Str;
15
+ readonly stderr: Str;
16
+ };
17
+ type GitFetchIn = {
18
+ readonly repoDir: Str;
19
+ readonly remote: Opt<string>;
20
+ readonly rev: Str;
21
+ };
22
+ type GitFetchOut = {
23
+ readonly fetched: Str;
24
+ readonly stdout: Str;
25
+ };
26
+ type GitGrepCountIn = {
27
+ readonly repoDir: Str;
28
+ readonly pattern: Str;
29
+ readonly paths: Opt<readonly string[]>;
30
+ };
31
+ type GitGrepCountRow = {
32
+ readonly file: string;
33
+ readonly count: number;
34
+ };
35
+ type NetworkIn = {
36
+ readonly scheme: Opt<"http" | "https">;
37
+ readonly authority: Str;
38
+ readonly method: Opt<"GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE">;
39
+ readonly path: Str;
40
+ readonly body: Opt<string>;
41
+ readonly secretRef: Opt<string>;
42
+ };
43
+ type NetworkOut = {
44
+ readonly status: Int;
45
+ readonly body: Str;
46
+ };
47
+ type ReadingPin = {
48
+ readonly branch: string;
49
+ readonly head: string;
50
+ };
51
+ type GitPushIn = {
52
+ readonly repoDir: Str;
53
+ readonly repo: Str;
54
+ readonly branch: Str;
55
+ readonly remote: Opt<string>;
56
+ readonly refspec: Opt<string>;
57
+ readonly force: Opt<boolean>;
58
+ readonly openReadingHeads: Opt<readonly ReadingPin[]>;
59
+ };
60
+ type GitPushOut = {
61
+ readonly repo: Str;
62
+ readonly remote: Str;
63
+ readonly branch: Str;
64
+ readonly localHead: Str;
65
+ readonly stdout: Str;
66
+ readonly stderr: Str;
67
+ };
68
+ type GithubApiIn = {
69
+ readonly apiScheme: Opt<"http" | "https">;
70
+ readonly apiAuthority: Opt<string>;
71
+ };
72
+ type GithubChecksIn = GithubApiIn & {
73
+ readonly repo: Str;
74
+ readonly head: Str;
75
+ };
76
+ type GithubCheckRow = {
77
+ readonly name: string;
78
+ readonly state: "green" | "pending" | "failed";
79
+ };
80
+ type GithubMergeIn = GithubApiIn & {
81
+ readonly repo: Str;
82
+ readonly pr: Int;
83
+ readonly head: Str;
84
+ readonly method: Opt<"merge" | "squash" | "rebase">;
85
+ readonly requiredChecks: Opt<readonly string[]>;
86
+ readonly requiredReadings: Opt<number>;
87
+ readonly readingHeads: Opt<readonly string[]>;
88
+ };
89
+ type GithubMergeOut = {
90
+ readonly merged: TypeDef<boolean>;
91
+ readonly sha: Str;
92
+ readonly message: Str;
93
+ };
94
+ /** The std actions. `process`, `gitFetch` and `gitGrepCount` run in the installation; list them in `defineInstallation({ actions })`. The rest run in the host. */
95
+ export interface StdActions {
96
+ readonly process: RunnableAction<"telar.std/action/process/1", In<ProcessIn>, StructContract<string, ProcessOut>>;
97
+ readonly gitFetch: RunnableAction<"telar.std/action/git-fetch/1", In<GitFetchIn>, StructContract<string, GitFetchOut>>;
98
+ readonly gitGrepCount: RunnableAction<"telar.std/action/git-grep-count/1", In<GitGrepCountIn>, Contract<string, TypeDef<readonly GitGrepCountRow[]>, readonly GitGrepCountRow[]>>;
99
+ readonly network: Action<"telar.std/action/network/1", In<NetworkIn>, StructContract<string, NetworkOut>>;
100
+ readonly gitPush: Action<"telar.std/action/git-push/1", In<GitPushIn>, StructContract<string, GitPushOut>>;
101
+ readonly githubChecks: Action<"telar.std/action/github-checks/1", In<GithubChecksIn>, Contract<string, TypeDef<readonly GithubCheckRow[]>, readonly GithubCheckRow[]>>;
102
+ readonly githubMerge: Action<"telar.std/action/github-merge/1", In<GithubMergeIn>, StructContract<string, GithubMergeOut>>;
103
+ }
104
+ export declare const stdActions: StdActions;
105
+ export {};
@@ -0,0 +1,153 @@
1
+ import { ActionError, declareAction, defineAction, } from "../pieces.js";
2
+ import { contract, t, } from "../schema.js";
3
+ const nonEmpty = () => t.string({ nonEmpty: true });
4
+ const strings = () => t.optional(t.array(t.string()));
5
+ const scheme = () => t.optional(t.enum(["http", "https"]));
6
+ function cleanRef(value, label) {
7
+ if (value === "" || value.startsWith("-") || value.startsWith("+") || !/^[!-~]+$/.test(value)) {
8
+ throw new ActionError("INVALID_INPUT", `invalid ${label} ${JSON.stringify(value)}`);
9
+ }
10
+ return value;
11
+ }
12
+ function git(powers, repoDir, args) {
13
+ return powers.process({ executable: "git", args, cwd: repoDir });
14
+ }
15
+ function gitFailed(out) {
16
+ return new ActionError("GIT_COMMAND_FAILED", out.stderr.trim());
17
+ }
18
+ function grepCounts(stdout) {
19
+ return stdout
20
+ .split("\n")
21
+ .map((line) => line.trim())
22
+ .filter((line) => line.length > 0)
23
+ .map((line) => {
24
+ const at = line.lastIndexOf(":");
25
+ const count = Number(line.slice(at + 1));
26
+ if (at < 0 || !/^[0-9]+$/.test(line.slice(at + 1)) || !Number.isSafeInteger(count)) {
27
+ throw new ActionError("GIT_COMMAND_FAILED", `unexpected git grep line ${JSON.stringify(line)}`);
28
+ }
29
+ return { file: line.slice(0, at), count };
30
+ });
31
+ }
32
+ const runProcess = defineAction({
33
+ id: "telar.std/action/process/1",
34
+ input: contract("std-process-in", {
35
+ executable: nonEmpty(),
36
+ args: strings(),
37
+ cwd: t.optional(t.string()),
38
+ }),
39
+ output: contract("std-process-out", {
40
+ exitCode: t.int(),
41
+ stdout: t.string(),
42
+ stderr: t.string(),
43
+ }),
44
+ run: ({ executable, args, cwd }, powers) => {
45
+ const out = powers.process({
46
+ executable,
47
+ ...(args !== undefined ? { args } : {}),
48
+ ...(cwd !== undefined ? { cwd } : {}),
49
+ });
50
+ return { exitCode: out.exitCode, stdout: out.stdout, stderr: out.stderr };
51
+ },
52
+ });
53
+ const gitFetch = defineAction({
54
+ id: "telar.std/action/git-fetch/1",
55
+ input: contract("std-git-fetch-in", {
56
+ repoDir: nonEmpty(),
57
+ remote: t.optional(t.string()),
58
+ rev: nonEmpty(),
59
+ }),
60
+ output: contract("std-git-fetch-out", { fetched: t.string(), stdout: t.string() }),
61
+ run: ({ repoDir, remote, rev }, powers) => {
62
+ const args = ["fetch", "-q", cleanRef(remote ?? "origin", "remote"), cleanRef(rev, "rev")];
63
+ const out = git(powers, repoDir, args);
64
+ if (out.exitCode !== 0)
65
+ throw gitFailed(out);
66
+ return { fetched: rev, stdout: out.stdout };
67
+ },
68
+ });
69
+ const gitGrepCount = defineAction({
70
+ id: "telar.std/action/git-grep-count/1",
71
+ input: contract("std-git-grep-count-in", {
72
+ repoDir: nonEmpty(),
73
+ pattern: nonEmpty(),
74
+ paths: strings(),
75
+ }),
76
+ output: contract("std-git-grep-count-out", t.array(t.struct({ file: t.string(), count: t.int({ min: 0 }) }))),
77
+ run: ({ repoDir, pattern, paths }, powers) => {
78
+ const out = git(powers, repoDir, ["grep", "-c", "-F", "--", pattern, ...(paths ?? [])]);
79
+ if (out.exitCode === 1 && out.stderr.trim() === "")
80
+ return [];
81
+ if (out.exitCode !== 0)
82
+ throw gitFailed(out);
83
+ return grepCounts(out.stdout);
84
+ },
85
+ });
86
+ const network = declareAction({
87
+ id: "telar.std/action/network/1",
88
+ input: contract("std-network-in", {
89
+ scheme: scheme(),
90
+ authority: nonEmpty(),
91
+ method: t.optional(t.enum(["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"])),
92
+ path: nonEmpty(),
93
+ body: t.optional(t.string()),
94
+ secretRef: t.optional(t.string({ nonEmpty: true })),
95
+ }),
96
+ output: contract("std-network-out", { status: t.int(), body: t.string() }),
97
+ });
98
+ const gitPush = declareAction({
99
+ id: "telar.std/action/git-push/1",
100
+ input: contract("std-git-push-in", {
101
+ repoDir: nonEmpty(),
102
+ repo: nonEmpty(),
103
+ branch: nonEmpty(),
104
+ remote: t.optional(t.string({ nonEmpty: true })),
105
+ refspec: t.optional(t.string({ nonEmpty: true })),
106
+ force: t.optional(t.boolean()),
107
+ openReadingHeads: t.optional(t.array(t.struct({ branch: nonEmpty(), head: nonEmpty() }))),
108
+ }),
109
+ output: contract("std-git-push-out", {
110
+ repo: t.string(),
111
+ remote: t.string(),
112
+ branch: t.string(),
113
+ localHead: t.string(),
114
+ stdout: t.string(),
115
+ stderr: t.string(),
116
+ }),
117
+ });
118
+ const githubApi = {
119
+ apiScheme: scheme(),
120
+ apiAuthority: t.optional(t.string({ nonEmpty: true })),
121
+ };
122
+ const githubChecks = declareAction({
123
+ id: "telar.std/action/github-checks/1",
124
+ input: contract("std-github-checks-in", { ...githubApi, repo: nonEmpty(), head: nonEmpty() }),
125
+ output: contract("std-github-checks-out", t.array(t.struct({ name: t.string(), state: t.enum(["green", "pending", "failed"]) }))),
126
+ });
127
+ const githubMerge = declareAction({
128
+ id: "telar.std/action/github-merge/1",
129
+ input: contract("std-github-merge-in", {
130
+ ...githubApi,
131
+ repo: nonEmpty(),
132
+ pr: t.int({ min: 1 }),
133
+ head: nonEmpty(),
134
+ method: t.optional(t.enum(["merge", "squash", "rebase"])),
135
+ requiredChecks: t.optional(t.array(nonEmpty())),
136
+ requiredReadings: t.optional(t.int({ min: 0 })),
137
+ readingHeads: t.optional(t.array(nonEmpty())),
138
+ }),
139
+ output: contract("std-github-merge-out", {
140
+ merged: t.boolean(),
141
+ sha: t.string(),
142
+ message: t.string(),
143
+ }),
144
+ });
145
+ export const stdActions = Object.freeze({
146
+ process: runProcess,
147
+ gitFetch,
148
+ gitGrepCount,
149
+ network,
150
+ gitPush,
151
+ githubChecks,
152
+ githubMerge,
153
+ });
@@ -0,0 +1,36 @@
1
+ import { type Brand, type Infer, type StructContract, type TypeDef } from "../spec.js";
2
+ export declare const PROSE_VALIDATOR_ID: "telar.std/prose/1";
3
+ export declare const BRIEF_VALIDATOR_ID: "telar.std/brief/2";
4
+ export declare const ENGINEERING_TEXT_MAX: 2000;
5
+ export declare const personText: TypeDef<Brand<string, "PersonText">>;
6
+ export declare function engineeringText(maxLength?: number, description?: string): TypeDef<string>;
7
+ export declare const optionId: TypeDef<Brand<string, "OptionId">>;
8
+ export declare const typedRef: StructContract<"typed-ref", {
9
+ readonly kind: TypeDef<string>;
10
+ readonly id: TypeDef<string>;
11
+ readonly title: TypeDef<string>;
12
+ }>;
13
+ export type StdTypedRef = Infer<typeof typedRef>;
14
+ export declare const briefOption: StructContract<"brief-option", {
15
+ readonly id: typeof optionId;
16
+ readonly label: TypeDef<string>;
17
+ readonly consequence: TypeDef<string>;
18
+ }>;
19
+ export type StdBriefOption = Infer<typeof briefOption>;
20
+ export declare const briefRecommendation: StructContract<"brief-recommendation", {
21
+ readonly optionId: typeof optionId;
22
+ readonly reason: TypeDef<string>;
23
+ }>;
24
+ export type StdBriefRecommendation = Infer<typeof briefRecommendation>;
25
+ export declare const briefUrgency: TypeDef<"low" | "normal" | "blocking">;
26
+ export type StdBriefUrgency = Infer<typeof briefUrgency>;
27
+ export declare const stdBrief: StructContract<"std-brief", {
28
+ readonly headline: TypeDef<string>;
29
+ readonly context: TypeDef<string>;
30
+ readonly ask: TypeDef<string>;
31
+ readonly options: TypeDef<readonly [StdBriefOption, ...StdBriefOption[]]>;
32
+ readonly recommendation: typeof briefRecommendation;
33
+ readonly evidence: TypeDef<readonly StdTypedRef[]>;
34
+ readonly urgency: typeof briefUrgency;
35
+ }>;
36
+ export type StdBrief = Infer<typeof stdBrief>;
@@ -0,0 +1,78 @@
1
+ import { contract, t } from "../spec.js";
2
+ export const PROSE_VALIDATOR_ID = "telar.std/prose/1";
3
+ export const BRIEF_VALIDATOR_ID = "telar.std/brief/2";
4
+ export const ENGINEERING_TEXT_MAX = 2000;
5
+ export const personText = t.string({
6
+ nonEmpty: true,
7
+ brand: "PersonText",
8
+ validator: PROSE_VALIDATOR_ID,
9
+ audience: "person",
10
+ });
11
+ export function engineeringText(maxLength = ENGINEERING_TEXT_MAX, description) {
12
+ return t.string({
13
+ nonEmpty: true,
14
+ maxLength,
15
+ audience: "agent",
16
+ ...(description !== undefined ? { description } : {}),
17
+ });
18
+ }
19
+ export const optionId = t.string({
20
+ nonEmpty: true,
21
+ brand: "OptionId",
22
+ audience: "agent",
23
+ description: "Stable identifier for this option",
24
+ });
25
+ const briefText = (maxLength, description) => t.string({ nonEmpty: true, maxLength, description, audience: "person" });
26
+ export const typedRef = contract("typed-ref", {
27
+ kind: t.string({
28
+ nonEmpty: true,
29
+ audience: "agent",
30
+ description: "Kind of referenced resource (for example, case, pr, project, repo)",
31
+ }),
32
+ id: t.string({
33
+ nonEmpty: true,
34
+ audience: "agent",
35
+ description: "Identifier of the referenced resource within its kind",
36
+ }),
37
+ title: t.string({
38
+ nonEmpty: true,
39
+ audience: "person",
40
+ description: "One-line human-readable title shown as the link label",
41
+ }),
42
+ });
43
+ export const briefOption = contract("brief-option", {
44
+ id: optionId,
45
+ label: briefText(40, "The option, in a few words"),
46
+ consequence: briefText(200, "What happens if this option is chosen"),
47
+ });
48
+ export const briefRecommendation = contract("brief-recommendation", {
49
+ optionId,
50
+ reason: briefText(200, "Why this option"),
51
+ }, {
52
+ description: "Recommended option id and why it wins",
53
+ audience: "person",
54
+ });
55
+ export const briefUrgency = t.enum(["low", "normal", "blocking"], {
56
+ description: "How urgently the reader must respond",
57
+ audience: "person",
58
+ examples: ["normal", "blocking"],
59
+ });
60
+ export const stdBrief = contract("std-brief", {
61
+ headline: briefText(80, "What happened, in one line"),
62
+ context: briefText(600, "Why it matters, with no id outside evidence"),
63
+ ask: briefText(140, "What is needed from the reader"),
64
+ options: t.array(briefOption, {
65
+ nonEmpty: true,
66
+ description: "Distinct choices with their consequences",
67
+ audience: "person",
68
+ }),
69
+ recommendation: briefRecommendation,
70
+ evidence: t.array(typedRef, {
71
+ description: "Typed references backing this Brief",
72
+ audience: "person",
73
+ }),
74
+ urgency: briefUrgency,
75
+ }, {
76
+ validator: BRIEF_VALIDATOR_ID,
77
+ description: "Structured Brief for a person",
78
+ });
@@ -0,0 +1,9 @@
1
+ import { type Runner } from "../runner.js";
2
+ export declare const CLAUDE_CODE_RUNNER_ID = "telar.std/runner/claude-code/1";
3
+ export type ClaudeCodeRunnerId = typeof CLAUDE_CODE_RUNNER_ID;
4
+ export interface ClaudeCodeRunnerOptions {
5
+ readonly model?: string | undefined;
6
+ readonly effort?: string | undefined;
7
+ }
8
+ /** std's Claude Code runner, built on `defineRunner` and `powers.process`. */
9
+ export declare const claudeCodeRunner: Runner<typeof CLAUDE_CODE_RUNNER_ID, ClaudeCodeRunnerOptions>;
@@ -0,0 +1,113 @@
1
+ import { RunnerError, defineRunner } from "../runner.js";
2
+ export const CLAUDE_CODE_RUNNER_ID = "telar.std/runner/claude-code/1";
3
+ const isRec = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
4
+ const optStr = (o, k) => typeof o[k] === "string" && o[k].length > 0 ? o[k] : undefined;
5
+ const optNum = (o, k) => typeof o[k] === "number" && Number.isFinite(o[k]) ? o[k] : undefined;
6
+ const claudeCodeOptionsSchema = {
7
+ "~standard": {
8
+ version: 1,
9
+ vendor: "telar.std",
10
+ validate(raw) {
11
+ if (raw === undefined)
12
+ return { value: {} };
13
+ if (!isRec(raw))
14
+ return { issues: [{ message: "options must be an object" }] };
15
+ const out = {};
16
+ for (const [k, v] of Object.entries(raw)) {
17
+ if (k !== "model" && k !== "effort") {
18
+ return {
19
+ issues: [
20
+ { path: [k], message: `unknown option ${JSON.stringify(k)}; allowed: model, effort` },
21
+ ],
22
+ };
23
+ }
24
+ if (typeof v !== "string" || v.trim().length === 0)
25
+ return { issues: [{ path: [k], message: "must be a non-empty string" }] };
26
+ out[k] = v;
27
+ }
28
+ return { value: out };
29
+ },
30
+ },
31
+ };
32
+ const USAGE_KEYS = [
33
+ ["input_tokens", "tokens.input"],
34
+ ["output_tokens", "tokens.output"],
35
+ ["cache_read_input_tokens", "tokens.cacheRead"],
36
+ ["cache_creation_input_tokens", "tokens.cacheWrite"],
37
+ ];
38
+ function parseOutput(stdout) {
39
+ const trimmed = stdout.trim();
40
+ if (!trimmed)
41
+ return {};
42
+ try {
43
+ const parsed = JSON.parse(trimmed);
44
+ if (isRec(parsed))
45
+ return parsed;
46
+ }
47
+ catch (err) {
48
+ throw new RunnerError("RUNNER_ERROR", `invalid claude JSON output: ${String(err)}`);
49
+ }
50
+ throw new RunnerError("RUNNER_ERROR", "claude JSON output must be an object");
51
+ }
52
+ function extractReadings(parsed) {
53
+ const out = {};
54
+ const put = (k, v) => {
55
+ if (v !== undefined)
56
+ out[k] = v;
57
+ };
58
+ put("usd", optNum(parsed, "total_cost_usd"));
59
+ const usage = parsed["usage"];
60
+ if (isRec(usage))
61
+ for (const [s, d] of USAGE_KEYS)
62
+ put(d, optNum(usage, s));
63
+ return out;
64
+ }
65
+ /** std's Claude Code runner, built on `defineRunner` and `powers.process`. */
66
+ export const claudeCodeRunner = defineRunner({
67
+ id: CLAUDE_CODE_RUNNER_ID,
68
+ options: claudeCodeOptionsSchema,
69
+ wake({ seat, prompt, ref, options }, powers) {
70
+ const args = ["-p", prompt, "--output-format", "json"];
71
+ if (ref !== undefined)
72
+ args.push("--resume", ref);
73
+ if (options.model !== undefined)
74
+ args.push("--model", options.model);
75
+ if (options.effort !== undefined)
76
+ args.push("--effort", options.effort);
77
+ const out = powers.process({
78
+ executable: "claude",
79
+ args,
80
+ env: { TELAR_SEAT: `${seat.installation}/${seat.seat}` },
81
+ });
82
+ if (out.exitCode !== 0) {
83
+ throw new RunnerError("RUNNER_ERROR", `claude turn failed (exit ${String(out.exitCode)}): ${out.stderr.trim()}`);
84
+ }
85
+ const parsed = parseOutput(out.stdout);
86
+ const runnerRef = optStr(parsed, "session_id") ?? ref ?? `claude:${seat.seat}`;
87
+ const model = optStr(parsed, "model") ?? options.model;
88
+ const holder = {
89
+ runner: "claude-code",
90
+ runtime: "claude-code",
91
+ ...(model ? { model } : {}),
92
+ ...(options.effort ? { effort: options.effort } : {}),
93
+ };
94
+ const id = optStr(parsed, "uuid") ?? `${runnerRef}:${out.startedAt}`;
95
+ const readings = extractReadings(parsed);
96
+ const evidence = Object.keys(readings).length > 0 ? { readings } : undefined;
97
+ return {
98
+ ref: runnerRef,
99
+ state: "idle",
100
+ holder,
101
+ work: [
102
+ {
103
+ id,
104
+ startedAt: out.startedAt,
105
+ endedAt: out.endedAt,
106
+ ...(evidence !== undefined ? { evidence } : {}),
107
+ },
108
+ ],
109
+ };
110
+ },
111
+ poll: ({ ref }) => ({ ref, state: "idle" }),
112
+ end: () => { },
113
+ });
@@ -0,0 +1,29 @@
1
+ import { type Check, type StructContract, type TypeDef } from "../spec.js";
2
+ export declare const COMPARE_EVALUATOR_ID: "telar.std/compare/1";
3
+ export type OrderCompareOp = "eq" | "ne" | "lt" | "le" | "gt" | "ge";
4
+ export type EqCompareOp = "eq" | "ne";
5
+ export declare const compareNumberArgs: StructContract<"compare-number-args", {
6
+ readonly left: TypeDef<number>;
7
+ readonly op: TypeDef<OrderCompareOp>;
8
+ readonly right: TypeDef<number>;
9
+ }>;
10
+ export declare const compareBoolArgs: StructContract<"compare-bool-args", {
11
+ readonly left: TypeDef<boolean>;
12
+ readonly op: TypeDef<EqCompareOp>;
13
+ readonly right: TypeDef<boolean>;
14
+ }>;
15
+ export declare const compareStringArgs: StructContract<"compare-string-args", {
16
+ readonly left: TypeDef<string>;
17
+ readonly op: TypeDef<EqCompareOp>;
18
+ readonly right: TypeDef<string>;
19
+ }>;
20
+ export interface StdCompareChecks<NS extends string = "telar"> {
21
+ readonly number: Check<`${NS}.compare-number`, typeof compareNumberArgs>;
22
+ readonly bool: Check<`${NS}.compare-bool`, typeof compareBoolArgs>;
23
+ readonly string: Check<`${NS}.compare-string`, typeof compareStringArgs>;
24
+ }
25
+ export declare function stdCompareChecks(): StdCompareChecks;
26
+ export declare function stdCompareChecks<const NS extends string>(namespace: NS): StdCompareChecks<NS>;
27
+ export declare const compareNumber: Check<"telar.compare-number", typeof compareNumberArgs>;
28
+ export declare const compareBool: Check<"telar.compare-bool", typeof compareBoolArgs>;
29
+ export declare const compareString: Check<"telar.compare-string", typeof compareStringArgs>;
@@ -0,0 +1,36 @@
1
+ import { check, contract, t } from "../spec.js";
2
+ export const COMPARE_EVALUATOR_ID = "telar.std/compare/1";
3
+ export const compareNumberArgs = contract("compare-number-args", {
4
+ left: t.int({ min: 0 }),
5
+ op: t.enum(["eq", "ne", "lt", "le", "gt", "ge"]),
6
+ right: t.int({ min: 0 }),
7
+ });
8
+ export const compareBoolArgs = contract("compare-bool-args", {
9
+ left: t.boolean(),
10
+ op: t.enum(["eq", "ne"]),
11
+ right: t.boolean(),
12
+ });
13
+ export const compareStringArgs = contract("compare-string-args", {
14
+ left: t.string({ nonEmpty: true }),
15
+ op: t.enum(["eq", "ne"]),
16
+ right: t.string({ nonEmpty: true }),
17
+ });
18
+ export function stdCompareChecks(namespace = "telar") {
19
+ return Object.freeze({
20
+ number: check(`${namespace}.compare-number`, {
21
+ input: compareNumberArgs,
22
+ evaluator: COMPARE_EVALUATOR_ID,
23
+ }),
24
+ bool: check(`${namespace}.compare-bool`, {
25
+ input: compareBoolArgs,
26
+ evaluator: COMPARE_EVALUATOR_ID,
27
+ }),
28
+ string: check(`${namespace}.compare-string`, {
29
+ input: compareStringArgs,
30
+ evaluator: COMPARE_EVALUATOR_ID,
31
+ }),
32
+ });
33
+ }
34
+ export const compareNumber = check("telar.compare-number", { input: compareNumberArgs, evaluator: COMPARE_EVALUATOR_ID });
35
+ export const compareBool = check("telar.compare-bool", { input: compareBoolArgs, evaluator: COMPARE_EVALUATOR_ID });
36
+ export const compareString = check("telar.compare-string", { input: compareStringArgs, evaluator: COMPARE_EVALUATOR_ID });
@@ -0,0 +1,44 @@
1
+ import type { WorldPowers } from "../powers.js";
2
+ import type { ProcessGrantDecl } from "../types.js";
3
+ export type GitWorkspaceErrorCode = "INVALID_SEGMENT" | "INVALID_REF" | "WORKSPACE_BUSY" | "GIT_COMMAND_FAILED";
4
+ export declare class GitWorkspaceError extends Error {
5
+ readonly name: string;
6
+ readonly code: GitWorkspaceErrorCode;
7
+ constructor(code: GitWorkspaceErrorCode, message: string);
8
+ }
9
+ /** A repo a seat works in: `base` is the remote branch a new worktree starts from. */
10
+ export interface GitRepo {
11
+ readonly id: string;
12
+ readonly url: string;
13
+ readonly base: string;
14
+ }
15
+ /** Absolute directories inside roots the host granted to the piece. */
16
+ export interface GitWorkspaceRoots {
17
+ readonly repos: string;
18
+ readonly workspaces: string;
19
+ }
20
+ export interface PreparedWorkspace {
21
+ readonly dir: string;
22
+ readonly repos: readonly {
23
+ readonly id: string;
24
+ readonly dir: string;
25
+ readonly branch: string;
26
+ }[];
27
+ }
28
+ export interface GitWorkspace {
29
+ prepare(input: {
30
+ readonly seat: string;
31
+ readonly branch: string;
32
+ readonly repos: readonly GitRepo[];
33
+ }): PreparedWorkspace;
34
+ remove(input: {
35
+ readonly seat: string;
36
+ readonly repos: readonly string[];
37
+ }): void;
38
+ }
39
+ /** The process grants `gitWorkspace` needs, one `git` subcommand each. */
40
+ export declare const GIT_WORKSPACE_GRANT: readonly ProcessGrantDecl[];
41
+ export declare const GIT_WORKSPACE_LOCK_REF = "refs/telar-workspace/lock";
42
+ export declare const GIT_WORKSPACE_LOCK_STALE_MS: number;
43
+ /** Gives each seat its own worktree of one or more repos, under `roots`, through `powers.process` and `git` only. */
44
+ export declare function gitWorkspace(powers: WorldPowers, roots: GitWorkspaceRoots): GitWorkspace;