Merge commit '67b361f0e99135c578d5764c915b413f457dd67a' as 'third_party/pi'

This commit is contained in:
2026-09-14 10:40:08 -04:00
1669 changed files with 397627 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
import { type Context, defineService, type ReplicatedState } from "@earendil-works/chord";
export interface ExampleFacetReply {
readonly message: string;
readonly workerActivations: number;
}
export interface ExampleFacetService {
readonly workerActivations: ReplicatedState<{ count: number }>;
greet(input: { readonly name: string }, context: Context): Promise<ExampleFacetReply>;
}
export const ExampleFacetService = defineService<ExampleFacetService>("pi.example-plugin.greeting");

View File

@@ -0,0 +1,23 @@
import { defineFacet } from "@earendil-works/chord";
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
import { ExampleFacetService } from "./contract.ts";
export default defineFacet({
id: "@earendil-works/pi-example-plugin/session",
setup(env) {
const workerActivations = env.replicatedState({ count: 0 });
env.provide(ExampleFacetService, {
workerActivations,
async greet({ name }) {
return {
message: `Hello ${name} from the bundled Session worker facet!!!`,
workerActivations: workerActivations.value.count,
};
},
});
env.onActivate(() => {
workerActivations.state.count += 1;
workerActivations.publish(BACKGROUND_CONTEXT);
});
},
});

View File

@@ -0,0 +1,31 @@
import { defineFacet } from "@earendil-works/chord";
import { AgentController, PresentationUI, SlashCommands } from "@earendil-works/pi-coding-agent/experimental/plugin";
import { ExampleFacetService } from "./contract.ts";
export default defineFacet({
id: "@earendil-works/pi-example-plugin/tui",
setup(env) {
const example = env.use(ExampleFacetService);
const commands = env.use(SlashCommands);
const controller = env.use(AgentController);
const ui = env.use(PresentationUI);
env.onActivate(() => {
env.own(
commands.replace({
name: "hello",
description: "Call the bundled Session worker facet",
argumentHint: "<name>",
async run(args, context) {
const message = args.length === 0 ? "from the TUI" : args;
const reply = await example.greet({ name: message }, context);
ui.showStatus(
`We got this: ${reply.message} Worker activations: ${reply.workerActivations}.`,
context,
);
return controller.prompt({ message: `pong: ${message}`, images: null }, context);
},
}),
);
});
},
});