@dxos/brain 0.0.1 → 0.12.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 (68) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +32 -1
  3. package/dist/lib/Builtins.mjs +178 -0
  4. package/dist/lib/Builtins.mjs.map +1 -0
  5. package/dist/lib/CompilePrompt.mjs +305 -0
  6. package/dist/lib/CompilePrompt.mjs.map +1 -0
  7. package/dist/lib/Compiler.mjs +212 -0
  8. package/dist/lib/Compiler.mjs.map +1 -0
  9. package/dist/lib/Encoding.mjs +116 -0
  10. package/dist/lib/Encoding.mjs.map +1 -0
  11. package/dist/lib/GoalRules.mjs +161 -0
  12. package/dist/lib/GoalRules.mjs.map +1 -0
  13. package/dist/lib/Vocabulary.mjs +92 -0
  14. package/dist/lib/Vocabulary.mjs.map +1 -0
  15. package/dist/lib/chunk-rolldown-runtime.mjs +13 -0
  16. package/dist/lib/index.mjs +7 -0
  17. package/dist/lib/testing.mjs +831 -0
  18. package/dist/lib/testing.mjs.map +1 -0
  19. package/dist/types/src/Builtins.d.ts +57 -0
  20. package/dist/types/src/Builtins.d.ts.map +1 -0
  21. package/dist/types/src/Builtins.test.d.ts +2 -0
  22. package/dist/types/src/Builtins.test.d.ts.map +1 -0
  23. package/dist/types/src/CompilePrompt.d.ts +107 -0
  24. package/dist/types/src/CompilePrompt.d.ts.map +1 -0
  25. package/dist/types/src/CompilePrompt.test.d.ts +2 -0
  26. package/dist/types/src/CompilePrompt.test.d.ts.map +1 -0
  27. package/dist/types/src/Compiler.d.ts +76 -0
  28. package/dist/types/src/Compiler.d.ts.map +1 -0
  29. package/dist/types/src/Compiler.test.d.ts +2 -0
  30. package/dist/types/src/Compiler.test.d.ts.map +1 -0
  31. package/dist/types/src/Encoding.d.ts +42 -0
  32. package/dist/types/src/Encoding.d.ts.map +1 -0
  33. package/dist/types/src/GoalRules.d.ts +66 -0
  34. package/dist/types/src/GoalRules.d.ts.map +1 -0
  35. package/dist/types/src/GoalRules.test.d.ts +2 -0
  36. package/dist/types/src/GoalRules.test.d.ts.map +1 -0
  37. package/dist/types/src/Vocabulary.d.ts +31 -0
  38. package/dist/types/src/Vocabulary.d.ts.map +1 -0
  39. package/dist/types/src/Vocabulary.test.d.ts +2 -0
  40. package/dist/types/src/Vocabulary.test.d.ts.map +1 -0
  41. package/dist/types/src/index.d.ts +7 -0
  42. package/dist/types/src/index.d.ts.map +1 -0
  43. package/dist/types/src/testing/index.d.ts +4 -0
  44. package/dist/types/src/testing/index.d.ts.map +1 -0
  45. package/dist/types/src/testing/reference.d.ts +9 -0
  46. package/dist/types/src/testing/reference.d.ts.map +1 -0
  47. package/dist/types/src/testing/scenarios.d.ts +73 -0
  48. package/dist/types/src/testing/scenarios.d.ts.map +1 -0
  49. package/dist/types/src/testing/simulate.d.ts +31 -0
  50. package/dist/types/src/testing/simulate.d.ts.map +1 -0
  51. package/dist/types/tsconfig.tsbuildinfo +1 -0
  52. package/package.json +74 -5
  53. package/src/Builtins.test.ts +45 -0
  54. package/src/Builtins.ts +274 -0
  55. package/src/CompilePrompt.test.ts +117 -0
  56. package/src/CompilePrompt.ts +376 -0
  57. package/src/Compiler.test.ts +85 -0
  58. package/src/Compiler.ts +234 -0
  59. package/src/Encoding.ts +99 -0
  60. package/src/GoalRules.test.ts +96 -0
  61. package/src/GoalRules.ts +181 -0
  62. package/src/Vocabulary.test.ts +48 -0
  63. package/src/Vocabulary.ts +88 -0
  64. package/src/index.ts +10 -0
  65. package/src/testing/index.ts +7 -0
  66. package/src/testing/reference.ts +91 -0
  67. package/src/testing/scenarios.ts +604 -0
  68. package/src/testing/simulate.ts +127 -0
@@ -0,0 +1,73 @@
1
+ /** A scripted fact; `concerns` stubs entity resolution and defaults to the subject. */
2
+ export type ScenarioFact = {
3
+ readonly id: string;
4
+ /** Handle of who said it, or `agent` for the agent's own actions. */
5
+ readonly speaker: string;
6
+ /** The words as said. */
7
+ readonly quote: string;
8
+ /** Subject entity handle. */
9
+ readonly s: string;
10
+ /** Predicate, before vocabulary canonicalization. */
11
+ readonly p: string;
12
+ /** Object entity handle or literal. */
13
+ readonly o: string;
14
+ /** Speech-act force of the utterance. */
15
+ readonly force: 'assertive' | 'directive' | 'commissive' | 'expressive';
16
+ /** `+` affirmed, `-` negated or refused, `?` open question or unknown. */
17
+ readonly polarity: '+' | '-' | '?';
18
+ readonly mood: 'declarative' | 'interrogative' | 'imperative';
19
+ /** Conversation or message the fact came from, e.g. `chat:general`. */
20
+ readonly source: string;
21
+ /** FactBank factuality: certainty (CT/PR/PS/U) and polarity (+/-/u). */
22
+ readonly factuality: 'CT+' | 'CT-' | 'PR+' | 'PR-' | 'PS+' | 'PS-' | 'CTu' | 'Uu';
23
+ /** Entity handles the fact is about; defaults to the subject. */
24
+ readonly concerns?: ReadonlyArray<string>;
25
+ };
26
+ export type ScenarioAction = {
27
+ readonly id: string;
28
+ /** Action name, e.g. `send_email`. */
29
+ readonly kind: string;
30
+ /** Named action arguments, e.g. `{ to: 'dima' }`. */
31
+ readonly args: Readonly<Record<string, string>>;
32
+ };
33
+ /** Expected effects of a step; `null` or absent means either outcome is acceptable. */
34
+ export type Expectation = {
35
+ readonly wake?: boolean | null;
36
+ readonly achieved?: boolean | null;
37
+ readonly holds?: boolean | null;
38
+ readonly blocks?: boolean | null;
39
+ };
40
+ export type Step = {
41
+ readonly id: string;
42
+ /** Simulated clock time (ISO) the step runs at. */
43
+ readonly at: string;
44
+ /** Human-readable description of what happens in the step. */
45
+ readonly note: string;
46
+ readonly facts?: ReadonlyArray<ScenarioFact>;
47
+ readonly actions?: ReadonlyArray<ScenarioAction>;
48
+ /** Subgoal ids that become `active` from this step on. */
49
+ readonly subgoals?: ReadonlyArray<string>;
50
+ /** Subgoal status overrides by subgoal id, e.g. `{ g_w2: 'achieved' }`. */
51
+ readonly status?: Readonly<Record<string, string>>;
52
+ readonly expect: Expectation;
53
+ };
54
+ /** A timeline for one of the BRAIN.md example goals. */
55
+ export type Scenario = {
56
+ /** Number of the example goal in BRAIN.md. */
57
+ readonly n: number;
58
+ /** Natural-language goal text. */
59
+ readonly goal: string;
60
+ /** Handle of the actor who owns the goal. */
61
+ readonly owner: string;
62
+ /** Source id of the conversation a session goal is scoped to. */
63
+ readonly session?: string;
64
+ readonly createdAt: string;
65
+ /** Owner-written guidance passed to the compiler as the goal's instructions. */
66
+ readonly context?: string;
67
+ readonly steps: ReadonlyArray<Step>;
68
+ /** At least one step of each group must wake (a time-driven wake with a tolerant schedule). */
69
+ readonly wakeOneOf?: ReadonlyArray<ReadonlyArray<string>>;
70
+ };
71
+ /** The eight BRAIN.md example goals, each a hand-written timeline with near misses. */
72
+ export declare const SCENARIOS: ReadonlyArray<Scenario>;
73
+ //# sourceMappingURL=scenarios.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scenarios.d.ts","sourceRoot":"","sources":["../../../../src/testing/scenarios.ts"],"names":[],"mappings":"AAIA,uFAAuF;AACvF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,yBAAyB;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,6BAA6B;IAC7B,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,YAAY,CAAC;IACxE,0EAA0E;IAC1E,QAAQ,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,eAAe,GAAG,YAAY,CAAC;IAC9D,uEAAuE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AAM,CAAC,CAAC;IAC1C,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B,CAAC;AAEF,wDAAwD;AACxD,MAAM,MAAM,QAAQ,GAAG;IACrB,8CAA8C;IAC9C,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,6CAA6C;IAC7C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,gFAAgF;IAChF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;IACpC,+FAA+F;IAC/F,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;CAC3D,CAAC;AA+BF,uFAAuF;AACvF,eAAO,MAAM,SAAS,EAAE,aAAa,CAAC,QAAQ,CA8e7C,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { RDF } from '@dxos/pipeline-rdf';
2
+ import * as GoalRules from '../GoalRules.ts';
3
+ import type * as Vocabulary from '../Vocabulary.ts';
4
+ import { type Scenario, type ScenarioFact } from './scenarios.ts';
5
+ export type StepResult = {
6
+ readonly id: string;
7
+ readonly wake: boolean;
8
+ readonly labels: ReadonlyArray<string>;
9
+ /** The wakes, with the fact ids behind each. */
10
+ readonly wakes: ReadonlyArray<GoalRules.Wake>;
11
+ readonly achieved: boolean;
12
+ readonly holds: boolean;
13
+ readonly blocks: boolean;
14
+ /** Expectations of this step the result violates. */
15
+ readonly failures: ReadonlyArray<string>;
16
+ };
17
+ export type SimulationResult = {
18
+ readonly ok: boolean;
19
+ readonly steps: ReadonlyArray<StepResult>;
20
+ readonly failures: ReadonlyArray<string>;
21
+ };
22
+ /** Converts a scripted fact to an `RDF.Fact` said (and recorded) at `saidAt`. */
23
+ export declare const toFact: (fact: ScenarioFact, saidAt: string) => RDF.Fact;
24
+ /**
25
+ * Replays a scenario against compiled goal rules and checks every step's expectations; a
26
+ * compile error or a runtime error is reported as a failure.
27
+ */
28
+ export declare const simulate: (scenario: Scenario, source: string, options?: {
29
+ vocabulary?: Vocabulary.Vocabulary;
30
+ }) => SimulationResult;
31
+ //# sourceMappingURL=simulate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simulate.d.ts","sourceRoot":"","sources":["../../../../src/testing/simulate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAG9C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,KAAK,UAAU,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAa,MAAM,gBAAgB,CAAC;AAE7E,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC1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