@aitoroses/telar 0.0.0-stage → 0.1.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 (92) hide show
  1. package/README.md +453 -2
  2. package/dist/compile.d.ts +48 -0
  3. package/dist/compile.js +1238 -0
  4. package/dist/contract.d.ts +109 -0
  5. package/dist/contract.js +497 -0
  6. package/dist/evaluator.d.ts +23 -0
  7. package/dist/evaluator.js +40 -0
  8. package/dist/guide.d.ts +8 -0
  9. package/dist/guide.js +16 -0
  10. package/dist/install.d.ts +104 -0
  11. package/dist/install.js +402 -0
  12. package/dist/iso.d.ts +8 -0
  13. package/dist/iso.js +68 -0
  14. package/dist/node/build.d.ts +1 -0
  15. package/dist/node/build.js +34 -0
  16. package/dist/node/telar-module.d.ts +2 -0
  17. package/dist/node/telar-module.js +28 -0
  18. package/dist/observer.d.ts +47 -0
  19. package/dist/observer.js +53 -0
  20. package/dist/pieces.d.ts +230 -0
  21. package/dist/pieces.js +178 -0
  22. package/dist/powers.d.ts +46 -0
  23. package/dist/powers.js +126 -0
  24. package/dist/protocol.d.ts +212 -0
  25. package/dist/protocol.js +236 -0
  26. package/dist/query.d.ts +67 -0
  27. package/dist/query.js +102 -0
  28. package/dist/read.d.ts +37 -0
  29. package/dist/read.js +27 -0
  30. package/dist/runner.d.ts +112 -0
  31. package/dist/runner.js +134 -0
  32. package/dist/scenario/builder.d.ts +25 -0
  33. package/dist/scenario/builder.js +603 -0
  34. package/dist/scenario/templates.d.ts +35 -0
  35. package/dist/scenario/templates.js +64 -0
  36. package/dist/scenario/types.d.ts +441 -0
  37. package/dist/scenario/types.js +10 -0
  38. package/dist/scenario/validate.d.ts +7 -0
  39. package/dist/scenario/validate.js +19 -0
  40. package/dist/scenario.d.ts +4 -0
  41. package/dist/scenario.js +4 -0
  42. package/dist/schema.d.ts +219 -0
  43. package/dist/schema.js +221 -0
  44. package/dist/seating.d.ts +49 -0
  45. package/dist/seating.js +26 -0
  46. package/dist/send-hook.d.ts +46 -0
  47. package/dist/send-hook.js +123 -0
  48. package/dist/show.d.ts +34 -0
  49. package/dist/show.js +1 -0
  50. package/dist/source.d.ts +85 -0
  51. package/dist/source.js +104 -0
  52. package/dist/spec.d.ts +20 -0
  53. package/dist/spec.js +17 -0
  54. package/dist/standard-schema.d.ts +21 -0
  55. package/dist/standard-schema.js +1 -0
  56. package/dist/std/accuracy.d.ts +12 -0
  57. package/dist/std/accuracy.js +122 -0
  58. package/dist/std/ack.d.ts +14 -0
  59. package/dist/std/ack.js +43 -0
  60. package/dist/std/actions.d.ts +106 -0
  61. package/dist/std/actions.js +154 -0
  62. package/dist/std/brief.d.ts +36 -0
  63. package/dist/std/brief.js +78 -0
  64. package/dist/std/claude-code.d.ts +9 -0
  65. package/dist/std/claude-code.js +106 -0
  66. package/dist/std/compare.d.ts +29 -0
  67. package/dist/std/compare.js +36 -0
  68. package/dist/std/git-workspace.d.ts +44 -0
  69. package/dist/std/git-workspace.js +184 -0
  70. package/dist/std/judgment.d.ts +85 -0
  71. package/dist/std/judgment.js +462 -0
  72. package/dist/std/observe-command.d.ts +23 -0
  73. package/dist/std/observe-command.js +151 -0
  74. package/dist/std/observe-github-checks.d.ts +26 -0
  75. package/dist/std/observe-github-checks.js +299 -0
  76. package/dist/std/observe-http-status.d.ts +27 -0
  77. package/dist/std/observe-http-status.js +181 -0
  78. package/dist/std/plan.d.ts +7 -0
  79. package/dist/std/plan.js +28 -0
  80. package/dist/std/queries.d.ts +31 -0
  81. package/dist/std/queries.js +318 -0
  82. package/dist/std/reading.d.ts +17 -0
  83. package/dist/std/reading.js +88 -0
  84. package/dist/std/schedule.d.ts +19 -0
  85. package/dist/std/schedule.js +122 -0
  86. package/dist/std.d.ts +15 -0
  87. package/dist/std.js +15 -0
  88. package/dist/types.d.ts +366 -0
  89. package/dist/types.js +1 -0
  90. package/dist/values.d.ts +81 -0
  91. package/dist/values.js +129 -0
  92. package/package.json +65 -3
@@ -0,0 +1,112 @@
1
+ import type { WorldPowers } from "./powers.js";
2
+ import type { SeatKey } from "./seating.js";
3
+ import type { StandardSchema } from "./standard-schema.js";
4
+ export type RunnerId = `${string}/runner/${string}/${number}`;
5
+ export interface RunnerSeatRef {
6
+ readonly installation: string;
7
+ readonly seat: string;
8
+ readonly role: string;
9
+ readonly binding: SeatKey;
10
+ }
11
+ export type RunnerState = "working" | "idle" | "ended";
12
+ export interface RunnerHolder {
13
+ readonly runner?: string | undefined;
14
+ readonly model?: string | undefined;
15
+ readonly effort?: string | undefined;
16
+ readonly account?: string | undefined;
17
+ readonly runtime?: string | undefined;
18
+ readonly thread?: string | undefined;
19
+ readonly ref?: never;
20
+ readonly [key: string]: string | undefined;
21
+ }
22
+ export interface RunnerReadings {
23
+ readonly "tokens.input"?: number | undefined;
24
+ readonly "tokens.output"?: number | undefined;
25
+ readonly "tokens.cacheRead"?: number | undefined;
26
+ readonly "tokens.cacheWrite"?: number | undefined;
27
+ readonly usd?: number | undefined;
28
+ readonly durationMs?: number | undefined;
29
+ readonly [key: string]: number | undefined;
30
+ }
31
+ export interface RunnerWork {
32
+ readonly id: string;
33
+ readonly startedAt: string;
34
+ readonly endedAt: string;
35
+ readonly readings: RunnerReadings;
36
+ }
37
+ export interface RunnerReport {
38
+ readonly ref: string;
39
+ readonly state: RunnerState;
40
+ readonly holder?: RunnerHolder;
41
+ readonly work?: readonly RunnerWork[];
42
+ }
43
+ export interface RunnerWakeInput<Options = Readonly<Record<string, unknown>>> {
44
+ readonly seat: RunnerSeatRef;
45
+ readonly prompt: string;
46
+ readonly ref?: string;
47
+ readonly options: Options;
48
+ }
49
+ export interface RunnerPollInput<Options = Readonly<Record<string, unknown>>> {
50
+ readonly ref: string;
51
+ readonly options: Options;
52
+ }
53
+ export interface RunnerEndInput<Options = Readonly<Record<string, unknown>>> {
54
+ readonly ref: string;
55
+ readonly options: Options;
56
+ }
57
+ export interface DefineRunnerInput<Id extends RunnerId = RunnerId, Options = Readonly<Record<string, unknown>>> {
58
+ readonly id: Id;
59
+ readonly options: StandardSchema<Options>;
60
+ readonly wake: (input: RunnerWakeInput<Options>, powers: WorldPowers) => RunnerReport;
61
+ readonly poll: (input: RunnerPollInput<Options>, powers: WorldPowers) => RunnerReport;
62
+ readonly end: (input: RunnerEndInput<Options>, powers: WorldPowers) => void;
63
+ }
64
+ export type RunnerPoint = "runner:wake" | "runner:poll" | "runner:end";
65
+ export interface RunnerOptionIssue {
66
+ readonly path: readonly string[];
67
+ readonly message: string;
68
+ }
69
+ export type RunnerOptionValidation<Options> = {
70
+ readonly ok: true;
71
+ readonly value: Options;
72
+ } | {
73
+ readonly ok: false;
74
+ readonly issues: readonly RunnerOptionIssue[];
75
+ };
76
+ export interface AnyRunner {
77
+ readonly id: RunnerId;
78
+ readonly options: StandardSchema;
79
+ readonly admitOptions: (raw: unknown) => RunnerOptionValidation<unknown>;
80
+ readonly dispatch: (point: RunnerPoint, args: unknown, powers: WorldPowers) => unknown;
81
+ }
82
+ export type RunnerIdOf<R> = R extends {
83
+ readonly id: infer Id extends RunnerId;
84
+ } ? Id : never;
85
+ export type RunnerOptionsOf<R> = R extends {
86
+ readonly options: StandardSchema<infer O>;
87
+ } ? O : never;
88
+ export interface Runner<Id extends RunnerId = RunnerId, Options = Readonly<Record<string, unknown>>> extends AnyRunner {
89
+ readonly id: Id;
90
+ readonly options: StandardSchema<Options>;
91
+ readonly wake: (input: RunnerWakeInput<Options>, powers: WorldPowers) => RunnerReport;
92
+ readonly poll: (input: RunnerPollInput<Options>, powers: WorldPowers) => RunnerReport;
93
+ readonly end: (input: RunnerEndInput<Options>, powers: WorldPowers) => void;
94
+ }
95
+ export declare class RunnerError extends Error {
96
+ readonly name: string;
97
+ readonly code: string;
98
+ constructor(code: string, message: string);
99
+ }
100
+ export declare function isValidRunnerId(id: string): boolean;
101
+ export type StandardValidation<Output> = {
102
+ readonly ok: true;
103
+ readonly value: Output;
104
+ } | {
105
+ readonly ok: false;
106
+ readonly issues: readonly RunnerOptionIssue[];
107
+ } | {
108
+ readonly ok: "async";
109
+ };
110
+ export declare function validateStandard<Output>(schema: StandardSchema<Output>, raw: unknown): StandardValidation<Output>;
111
+ export declare function validateRunnerOptions<Options>(runner: Pick<DefineRunnerInput<RunnerId, Options>, "id" | "options">, raw: unknown): RunnerOptionValidation<Options>;
112
+ export declare function defineRunner<const Id extends RunnerId, Options>(input: DefineRunnerInput<Id, Options>): Runner<Id, Options>;
package/dist/runner.js ADDED
@@ -0,0 +1,134 @@
1
+ export class RunnerError extends Error {
2
+ name = "RunnerError";
3
+ code;
4
+ constructor(code, message) {
5
+ super(message);
6
+ this.code = code;
7
+ }
8
+ }
9
+ const RUNNER_ID_RE = /^[a-z][a-z0-9.-]*\/runner\/[a-z][a-z0-9-]*\/[1-9][0-9]*$/;
10
+ export function isValidRunnerId(id) {
11
+ return RUNNER_ID_RE.test(id);
12
+ }
13
+ function isPromiseLike(value) {
14
+ return (typeof value === "object" && value !== null && typeof Reflect.get(value, "then") === "function");
15
+ }
16
+ function issuePath(issue) {
17
+ return (issue.path ?? []).map((part) => String(typeof part === "object" ? part.key : part));
18
+ }
19
+ function isRec(value) {
20
+ return typeof value === "object" && value !== null && !Array.isArray(value);
21
+ }
22
+ function reqNonEmpty(obj, key) {
23
+ const val = obj[key];
24
+ if (typeof val !== "string" || val.length === 0) {
25
+ throw new RunnerError("INVALID_INPUT", `runner:wake seat.binding.${key} must be a non-empty string`);
26
+ }
27
+ return val;
28
+ }
29
+ function readSeatKey(raw) {
30
+ if (!isRec(raw) || typeof raw["kind"] !== "string") {
31
+ throw new RunnerError("INVALID_INPUT", "runner:wake requires seat.binding SeatKey");
32
+ }
33
+ const kind = raw["kind"];
34
+ if (kind === "all")
35
+ return { kind: "all" };
36
+ if (kind === "case")
37
+ return { kind: "case", case_id: reqNonEmpty(raw, "case_id") };
38
+ if (kind === "field") {
39
+ return { kind: "field", field: reqNonEmpty(raw, "field"), value: reqNonEmpty(raw, "value") };
40
+ }
41
+ if (kind === "ancestor") {
42
+ return {
43
+ kind: "ancestor",
44
+ protocol: reqNonEmpty(raw, "protocol"),
45
+ case_id: reqNonEmpty(raw, "case_id"),
46
+ };
47
+ }
48
+ throw new RunnerError("INVALID_INPUT", `unknown seat.binding kind ${JSON.stringify(kind)}`);
49
+ }
50
+ function readSeatRef(raw) {
51
+ if (!isRec(raw) ||
52
+ typeof raw["installation"] !== "string" ||
53
+ typeof raw["seat"] !== "string" ||
54
+ typeof raw["role"] !== "string") {
55
+ throw new RunnerError("INVALID_INPUT", "runner:wake requires seat {installation, seat, role, binding}");
56
+ }
57
+ return {
58
+ installation: raw["installation"],
59
+ seat: raw["seat"],
60
+ role: raw["role"],
61
+ binding: readSeatKey(raw["binding"]),
62
+ };
63
+ }
64
+ export function validateStandard(schema, raw) {
65
+ const result = schema["~standard"].validate(raw);
66
+ if (isPromiseLike(result)) {
67
+ return { ok: "async" };
68
+ }
69
+ if (result.issues !== undefined) {
70
+ return {
71
+ ok: false,
72
+ issues: result.issues.map((issue) => ({
73
+ path: issuePath(issue),
74
+ message: issue.message,
75
+ })),
76
+ };
77
+ }
78
+ return { ok: true, value: result.value };
79
+ }
80
+ export function validateRunnerOptions(runner, raw) {
81
+ const checked = validateStandard(runner.options, raw === undefined ? {} : raw);
82
+ if (checked.ok === "async") {
83
+ throw new RunnerError("INVALID_RUNNER", `runner ${runner.id} options schema must validate synchronously`);
84
+ }
85
+ return checked;
86
+ }
87
+ export function defineRunner(input) {
88
+ if (!isValidRunnerId(input.id)) {
89
+ throw new RunnerError("INVALID_RUNNER", `runner id ${JSON.stringify(input.id)} must match <installation>/runner/<name>/<v>`);
90
+ }
91
+ const std = input.options["~standard"];
92
+ if (std.version !== 1 || typeof std.validate !== "function") {
93
+ throw new RunnerError("INVALID_RUNNER", `runner ${input.id} options must be a Standard Schema v1`);
94
+ }
95
+ const admitOptions = (raw) => validateRunnerOptions(input, raw);
96
+ const dispatch = (point, args, powers) => {
97
+ const rawOptions = isRec(args) ? args["options"] : undefined;
98
+ const validated = admitOptions(rawOptions);
99
+ if (!validated.ok) {
100
+ const first = validated.issues[0];
101
+ const path = first !== undefined && first.path.length > 0 ? `${first.path.join(".")}: ` : "";
102
+ throw new RunnerError("INVALID_SEATING", `${path}${first?.message ?? "invalid options"}`);
103
+ }
104
+ if (point === "runner:wake") {
105
+ if (!isRec(args) || typeof args["prompt"] !== "string") {
106
+ throw new RunnerError("INVALID_INPUT", "runner:wake requires a string prompt");
107
+ }
108
+ const ref = typeof args["ref"] === "string" ? args["ref"] : undefined;
109
+ return input.wake({
110
+ seat: readSeatRef(args["seat"]),
111
+ prompt: args["prompt"],
112
+ ...(ref !== undefined ? { ref } : {}),
113
+ options: validated.value,
114
+ }, powers);
115
+ }
116
+ if (!isRec(args) || typeof args["ref"] !== "string" || args["ref"].length === 0) {
117
+ throw new RunnerError("INVALID_INPUT", `${point} requires a non-empty string ref`);
118
+ }
119
+ if (point === "runner:poll") {
120
+ return input.poll({ ref: args["ref"], options: validated.value }, powers);
121
+ }
122
+ input.end({ ref: args["ref"], options: validated.value }, powers);
123
+ return {};
124
+ };
125
+ return Object.freeze({
126
+ id: input.id,
127
+ options: input.options,
128
+ wake: input.wake,
129
+ poll: input.poll,
130
+ end: input.end,
131
+ admitOptions,
132
+ dispatch,
133
+ });
134
+ }
@@ -0,0 +1,25 @@
1
+ import { type CaseBindingDescriptor, type ConfigInput, type EmptyBindings, type MessageBindingDescriptor, type MessageKindInput, type ProtocolInput, type RoleInput, type ScenarioBuilder, type ScenarioInit, type SeatBindingDescriptor, type SourceNames } from "./types.js";
2
+ export declare const absent: {
3
+ readonly $absent: true;
4
+ };
5
+ export declare function contains(substring: string): {
6
+ readonly $contains: string;
7
+ };
8
+ export declare function bindCase<const P extends string, const Par extends string = never>(protocol: ProtocolInput<P>, opts?: {
9
+ readonly parent?: Par | undefined;
10
+ readonly forRole?: RoleInput | undefined;
11
+ readonly scope?: string | undefined;
12
+ readonly index?: number | undefined;
13
+ }): CaseBindingDescriptor<Record<Par, string>, P>;
14
+ export declare function bindSeatRef<const R extends string, const C extends string = never>(role: RoleInput<R>, opts?: {
15
+ readonly case?: C | undefined;
16
+ readonly scope?: string | undefined;
17
+ readonly index?: number | undefined;
18
+ }): SeatBindingDescriptor<Record<C, string>, R>;
19
+ export declare function bindMessage<const MK extends string, const C extends string = never>(messageKind: MessageKindInput<MK>, opts?: {
20
+ readonly case?: C | undefined;
21
+ readonly index?: number | undefined;
22
+ }): MessageBindingDescriptor<Record<C, string>, MK>;
23
+ export declare function scenario<const Cfg extends ConfigInput | undefined = undefined>(init: ScenarioInit & {
24
+ readonly config?: Cfg;
25
+ }): ScenarioBuilder<EmptyBindings, EmptyBindings, EmptyBindings, SourceNames<Cfg>>;