@llm4ts/shell 4.8.0 → 4.10.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.
@@ -0,0 +1,143 @@
1
+ import * as Cause from "effect/Cause";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Ref from "effect/Ref";
4
+ import * as Schema from "effect/Schema";
5
+ import { ChiefAction, ChiefContext } from "@llm4ts/flow/ChiefAction";
6
+ import { type FlowError, type PersistenceError } from "@llm4ts/flow/FlowError";
7
+ import type { GitToolShape } from "@llm4ts/flow/GitTool";
8
+ import { GwsLoginRequired, type ChatMessage, type GoogleChatToolShape, type SpaceRef } from "@llm4ts/flow/GoogleChatTool";
9
+ import type { PlainFileStoreShape } from "@llm4ts/flow/Persistence";
10
+ import { type PlainProgress } from "@llm4ts/runner/RunSummary";
11
+ import { ChatState } from "./ChatState.ts";
12
+ import { type RunSources } from "./RunReaders.ts";
13
+ import type { RunSupervisorShape, SupervisorRepo } from "./RunSupervisor.ts";
14
+ /**
15
+ * The chat loop (`llm4ts chat`): one beat lists the space's new messages,
16
+ * keeps the `/bot` requests of allowed people, has the Chief decide one typed
17
+ * action per request, acts on it and replies in the request's thread.
18
+ */
19
+ export interface ChatOptions {
20
+ readonly space: SpaceRef;
21
+ readonly trigger: string;
22
+ readonly marker: string;
23
+ /** User resource names (`users/…`) allowed besides the owner. */
24
+ readonly allow: ReadonlyArray<string>;
25
+ /** The flows the Chief may start. */
26
+ readonly flows: ReadonlyArray<string>;
27
+ readonly intervalSeconds: number;
28
+ /** Post and start nothing; tell the terminal what would happen. */
29
+ readonly observe: boolean;
30
+ }
31
+ export interface ChatLoopDeps {
32
+ readonly chat: GoogleChatToolShape;
33
+ readonly files: PlainFileStoreShape;
34
+ readonly supervisor: RunSupervisorShape;
35
+ readonly git: GitToolShape;
36
+ readonly repo: SupervisorRepo;
37
+ readonly flows: Effect.Effect<ReadonlyArray<{
38
+ readonly name: string;
39
+ readonly path: string;
40
+ readonly description: string;
41
+ }>>;
42
+ readonly sources: RunSources;
43
+ /** Absolute trace paths under one `.llm4ts/` directory. */
44
+ readonly listTraces: (directory: string) => ReadonlyArray<string>;
45
+ /** Folder names under `.llm4ts/epics/`. */
46
+ readonly listEpics: (directory: string) => ReadonlyArray<string>;
47
+ readonly decide: (context: ChiefContext) => Effect.Effect<ChiefAction>;
48
+ readonly environment: Readonly<Record<string, string | undefined>>;
49
+ readonly now: Effect.Effect<number>;
50
+ /** The verb's terminal. */
51
+ readonly say: (line: string) => Effect.Effect<void>;
52
+ /** Senders already told who may ask; one reply each per process. */
53
+ readonly strangers: Ref.Ref<ReadonlySet<string>>;
54
+ /** Why the reasoning seat may not hold the Chief (`readOnlySeatProblem`), or undefined. */
55
+ readonly seatProblem: Effect.Effect<string | undefined>;
56
+ /** Whether the repository's git ignores `.llm4ts/`. */
57
+ readonly ignored: Effect.Effect<boolean>;
58
+ readonly options: ChatOptions;
59
+ }
60
+ export type Selected = {
61
+ readonly _tag: "Request";
62
+ readonly message: ChatMessage;
63
+ readonly body: string;
64
+ } | {
65
+ readonly _tag: "Help";
66
+ readonly message: ChatMessage;
67
+ } | {
68
+ readonly _tag: "Stranger";
69
+ readonly message: ChatMessage;
70
+ };
71
+ export declare const strangerReply = "Only the person who started me, or people they allowed, can ask me to do things here.";
72
+ export declare const helpReply: (options: ChatOptions) => string;
73
+ /**
74
+ * Which messages to act on. This decides who may start coding runs: only a
75
+ * person (`HUMAN`) who is the owner or named in `allow`, and with no owner id
76
+ * nobody at all, `allow` included. The Chief's own messages are known by
77
+ * name and by marker.
78
+ */
79
+ export declare const selectRequests: (state: ChatState, messages: ReadonlyArray<ChatMessage>, options: ChatOptions) => {
80
+ readonly selected: ReadonlyArray<Selected>;
81
+ readonly cursor: string;
82
+ };
83
+ /**
84
+ * One pass: list what is new since the cursor, then handle each selected
85
+ * message in order. Only a failed list and a lapsed login end the beat, so
86
+ * the caller can back off or stop; anything else is answered or told to the
87
+ * terminal, and the cursor moves past the message either way.
88
+ */
89
+ export declare const handleBeat: (deps: ChatLoopDeps, state: ChatState) => Effect.Effect<ChatState, GwsLoginRequired | FlowError>;
90
+ /** How long the loop waits for one decision before it stops the chief run. */
91
+ export declare const decideTimeoutMs = 120000;
92
+ /**
93
+ * The Chief's decision made by the bundled `chief` flow: the context goes to
94
+ * a file, the flow runs as a read-only supervised run, and its action file is
95
+ * read once it exits. Anything short of a clean exit within `decideTimeoutMs`
96
+ * and a decodable action is `Failed`, and the terminal is told why, with the
97
+ * chief run's id and where its logs are.
98
+ */
99
+ export declare const decideThroughFlow: (deps: Omit<ChatLoopDeps, "decide">) => (context: ChiefContext) => Effect.Effect<ChiefAction>;
100
+ /** At most one progress line per run in this window; the ending line is never held back. */
101
+ export declare const throttleMs = 30000;
102
+ /** Where the loop stands with one run started from chat. */
103
+ export interface Followed {
104
+ readonly runId: string;
105
+ /** The trace seq the last story-shaped line covered. */
106
+ readonly seq: number;
107
+ /** The plan progress the last plain line reported. */
108
+ readonly progress: PlainProgress | undefined;
109
+ readonly lastPostedAt: number;
110
+ readonly done: boolean;
111
+ }
112
+ export declare const startFollowing: (runId: string) => Followed;
113
+ /**
114
+ * One look at a run started from chat: post what changed into the thread of
115
+ * the request that started it, at most once per `throttleMs`, and its end
116
+ * always, once. A failed post is told to the terminal and tried again next
117
+ * time; only a lapsed login fails.
118
+ */
119
+ export declare const followRun: (deps: ChatLoopDeps, state: ChatState, followed: Followed) => Effect.Effect<{
120
+ readonly followed: Followed;
121
+ readonly state: ChatState;
122
+ }, GwsLoginRequired | PersistenceError>;
123
+ declare const ChatStopped_base: Schema.Class<ChatStopped, Schema.TaggedStruct<"ChatStopped", {
124
+ readonly message: Schema.String;
125
+ }>, Cause.YieldableError>;
126
+ export declare class ChatStopped extends ChatStopped_base {
127
+ }
128
+ /**
129
+ * The start checks, then the state: `gws` answers its probe, the space can be
130
+ * listed, and the reasoning seat enforces read-only. A new state starts its
131
+ * cursor now, so old `/bot` messages are not replayed. Unless `observe`, the
132
+ * Chief says it is listening, and whoever that line is posted as is the owner.
133
+ */
134
+ export declare const startChat: (deps: ChatLoopDeps) => Effect.Effect<ChatState, ChatStopped | PersistenceError>;
135
+ /**
136
+ * `startChat`, then forever: one beat, a look at every run started from chat,
137
+ * the state saved, a sleep. A failed list backs off, and a file that cannot
138
+ * be read or written is told to the terminal; neither ends the loop, a lapsed
139
+ * login does.
140
+ */
141
+ export declare const runChat: (deps: ChatLoopDeps) => Effect.Effect<never, ChatStopped | PersistenceError>;
142
+ export {};
143
+ //# sourceMappingURL=ChatLoop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatLoop.d.ts","sourceRoot":"","sources":["../src/ChatLoop.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,GAAG,MAAM,YAAY,CAAA;AACjC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,YAAY,EAA8B,MAAM,0BAA0B,CAAA;AAChG,OAAO,EAAqB,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACjG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EACL,gBAAgB,EAChB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACd,MAAM,6BAA6B,CAAA;AAEpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAGnE,OAAO,EAAoC,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAChG,OAAO,EAEL,SAAS,EAOV,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EAKL,KAAK,UAAU,EAEhB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;A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