@graview/tools 0.1.48 → 0.1.50

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 (106) hide show
  1. package/README.md +31 -0
  2. package/dist/agent/not-now.d.ts +12 -0
  3. package/dist/agent/not-now.d.ts.map +1 -0
  4. package/dist/agent/not-now.js +132 -0
  5. package/dist/agent/not-now.js.map +1 -0
  6. package/dist/agent/tools.d.ts +3 -2
  7. package/dist/agent/tools.d.ts.map +1 -1
  8. package/dist/agent/tools.js +48 -12
  9. package/dist/agent/tools.js.map +1 -1
  10. package/dist/agent/untrusted.d.ts.map +1 -1
  11. package/dist/agent/untrusted.js +3 -2
  12. package/dist/agent/untrusted.js.map +1 -1
  13. package/dist/ai.d.ts +1 -1
  14. package/dist/ai.d.ts.map +1 -1
  15. package/dist/cli.d.ts +3 -0
  16. package/dist/cli.d.ts.map +1 -1
  17. package/dist/cli.js +91 -4
  18. package/dist/cli.js.map +1 -1
  19. package/dist/decide.d.ts +1 -1
  20. package/dist/decide.d.ts.map +1 -1
  21. package/dist/decide.js +2 -2
  22. package/dist/decide.js.map +1 -1
  23. package/dist/derive.d.ts.map +1 -1
  24. package/dist/derive.js +8 -1
  25. package/dist/derive.js.map +1 -1
  26. package/dist/dev-ai.d.ts +2 -1
  27. package/dist/dev-ai.d.ts.map +1 -1
  28. package/dist/dev-ai.js +8 -6
  29. package/dist/dev-ai.js.map +1 -1
  30. package/dist/draft.js +1 -1
  31. package/dist/draft.js.map +1 -1
  32. package/dist/fast.d.ts +44 -0
  33. package/dist/fast.d.ts.map +1 -0
  34. package/dist/fast.js +2 -0
  35. package/dist/fast.js.map +1 -0
  36. package/dist/figure.js +1 -1
  37. package/dist/figure.js.map +1 -1
  38. package/dist/index.d.ts +4 -2
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1 -0
  41. package/dist/index.js.map +1 -1
  42. package/dist/inline-ai.d.ts.map +1 -1
  43. package/dist/inline-ai.js +1 -1
  44. package/dist/inline-ai.js.map +1 -1
  45. package/dist/intelligence.d.ts +32 -2
  46. package/dist/intelligence.d.ts.map +1 -1
  47. package/dist/intelligence.js +1 -1
  48. package/dist/intelligence.js.map +1 -1
  49. package/dist/local.d.ts +1 -1
  50. package/dist/local.d.ts.map +1 -1
  51. package/dist/local.js +23 -18
  52. package/dist/local.js.map +1 -1
  53. package/dist/loop.d.ts +1 -1
  54. package/dist/loop.d.ts.map +1 -1
  55. package/dist/loop.js.map +1 -1
  56. package/dist/providers/jev.d.ts +1 -36
  57. package/dist/providers/jev.d.ts.map +1 -1
  58. package/dist/providers/jev.js.map +1 -1
  59. package/dist/questions.js +2 -2
  60. package/dist/questions.js.map +1 -1
  61. package/dist/run.d.ts +1 -1
  62. package/dist/run.d.ts.map +1 -1
  63. package/dist/seat-model.d.ts +1 -1
  64. package/dist/seat-model.js +4 -4
  65. package/dist/seat-model.js.map +1 -1
  66. package/dist/suggest.d.ts +8 -8
  67. package/dist/suggest.d.ts.map +1 -1
  68. package/dist/suggest.js +2 -2
  69. package/dist/suggest.js.map +1 -1
  70. package/dist/tidy/asking.d.ts +51 -0
  71. package/dist/tidy/asking.d.ts.map +1 -0
  72. package/dist/tidy/asking.js +86 -0
  73. package/dist/tidy/asking.js.map +1 -0
  74. package/dist/tidy/away.d.ts +24 -0
  75. package/dist/tidy/away.d.ts.map +1 -0
  76. package/dist/tidy/away.js +24 -0
  77. package/dist/tidy/away.js.map +1 -0
  78. package/dist/tidy/blocking.d.ts +82 -0
  79. package/dist/tidy/blocking.d.ts.map +1 -0
  80. package/dist/tidy/blocking.js +260 -0
  81. package/dist/tidy/blocking.js.map +1 -0
  82. package/dist/tidy/dream.d.ts +117 -0
  83. package/dist/tidy/dream.d.ts.map +1 -0
  84. package/dist/tidy/dream.js +178 -0
  85. package/dist/tidy/dream.js.map +1 -0
  86. package/dist/tidy/judges.d.ts +109 -0
  87. package/dist/tidy/judges.d.ts.map +1 -0
  88. package/dist/tidy/judges.js +282 -0
  89. package/dist/tidy/judges.js.map +1 -0
  90. package/dist/tidy/judging.d.ts +51 -0
  91. package/dist/tidy/judging.d.ts.map +1 -0
  92. package/dist/tidy/judging.js +243 -0
  93. package/dist/tidy/judging.js.map +1 -0
  94. package/dist/tidy/policy.d.ts +18 -0
  95. package/dist/tidy/policy.d.ts.map +1 -0
  96. package/dist/tidy/policy.js +29 -0
  97. package/dist/tidy/policy.js.map +1 -0
  98. package/dist/tidy/system-one.d.ts +40 -0
  99. package/dist/tidy/system-one.d.ts.map +1 -0
  100. package/dist/tidy/system-one.js +49 -0
  101. package/dist/tidy/system-one.js.map +1 -0
  102. package/dist/tidy.d.ts +8 -0
  103. package/dist/tidy.d.ts.map +1 -0
  104. package/dist/tidy.js +23 -0
  105. package/dist/tidy.js.map +1 -0
  106. package/package.json +7 -3
@@ -0,0 +1,24 @@
1
+ import type { AnySchema, Principal, Store } from "@graview/core";
2
+ import { type ActivityRow } from "@graview/core/tidying";
3
+ /** Since when: a position in the log (`seq`, the first op not yet seen) or a moment (`at`, ISO). */
4
+ export interface AwaySince {
5
+ readonly seq?: number;
6
+ readonly at?: string;
7
+ }
8
+ export interface WhileAway {
9
+ /** Suggestions waiting now, whenever they were made. */
10
+ readonly waiting: number;
11
+ /** Of those, the ones made since. */
12
+ readonly suggestedSince: number;
13
+ /** How many things the actor did on its own since, not counting what was taken back. */
14
+ readonly tidied: number;
15
+ /** Activity's digest rows since: each run of the actor's changes as one row. */
16
+ readonly digests: readonly Extract<ActivityRow, {
17
+ digest: unknown;
18
+ }>["digest"][];
19
+ /** "3 suggestions waiting · tidied 12 things while you were away", or undefined when there is nothing to say. */
20
+ readonly said: string | undefined;
21
+ }
22
+ /** What the app's own actor did and suggested since `since`, as `principal` (or the seat a seat's store is of) may see it. */
23
+ export declare function whileAway<S extends AnySchema>(store: Store<S>, since: AwaySince, principal?: Principal): WhileAway;
24
+ //# sourceMappingURL=away.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"away.d.ts","sourceRoot":"","sources":["../../src/tidy/away.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAA4B,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAUnF,oGAAoG;AACpG,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qCAAqC;IACrC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,wFAAwF;IACxF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,CAAC,WAAW,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;IACjF,iHAAiH;IACjH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,8HAA8H;AAC9H,wBAAgB,SAAS,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAoBlH"}
@@ -0,0 +1,24 @@
1
+ import { foldDigests, suggestions } from "@graview/core/tidying";
2
+ /** What the app's own actor did and suggested since `since`, as `principal` (or the seat a seat's store is of) may see it. */
3
+ export function whileAway(store, since, principal) {
4
+ const seen = principal ? store.seenBy(principal) : store;
5
+ const after = (op) => (since.seq === undefined || op.seq >= since.seq) && (since.at === undefined || op.at > since.at);
6
+ const waitingNow = suggestions(seen);
7
+ const ops = seen.log.all();
8
+ const byId = new Map(ops.map((op) => [op.id, op]));
9
+ const seqOf = (id) => byId.get(id);
10
+ const suggestedSince = waitingNow.filter((one) => {
11
+ const op = seqOf(one.id);
12
+ return op !== undefined && after(op);
13
+ }).length;
14
+ const batches = seen.batches().filter((batch) => batch.ops.length > 0 && after(batch.ops[0]));
15
+ const digests = foldDigests(batches, (id) => byId.get(id)).flatMap((row) => ("digest" in row ? [row.digest] : []));
16
+ const tidied = digests.reduce((sum, digest) => sum + digest.things, 0);
17
+ const parts = [
18
+ waitingNow.length > 0 ? `${waitingNow.length === 1 ? "one suggestion" : `${waitingNow.length} suggestions`} waiting` : "",
19
+ tidied > 0 ? `tidied ${tidied === 1 ? "one thing" : `${tidied} things`} while you were away` : "",
20
+ ].filter(Boolean);
21
+ const said = parts.length > 0 ? parts.join(" · ").replace(/^./, (first) => first.toUpperCase()) : undefined;
22
+ return { waiting: waitingNow.length, suggestedSince, tidied, digests, said };
23
+ }
24
+ //# sourceMappingURL=away.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"away.js","sourceRoot":"","sources":["../../src/tidy/away.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAoB,MAAM,uBAAuB,CAAC;AA6BnF,8HAA8H;AAC9H,MAAM,UAAU,SAAS,CAAsB,KAAe,EAAE,KAAgB,EAAE,SAAqB;IACrG,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACzD,MAAM,KAAK,GAAG,CAAC,EAAiD,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,KAAK,SAAS,IAAI,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,SAAS,IAAI,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;IACtK,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAA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,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,cAAc,UAAU,CAAC,CAAC,CAAC,EAAE;QACzH,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,SAAS,sBAAsB,CAAC,CAAC,CAAC,EAAE;KAClG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClB,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5G,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,82 @@
1
+ import { type SearchRanker } from "@graview/core";
2
+ import { type JudgeContext } from "./judges.js";
3
+ type Node = {
4
+ readonly id: string;
5
+ readonly kind: string;
6
+ } & Record<string, unknown>;
7
+ /** Two records of one kind that may be one: the one that would stay, the one merged into it, and why they were paired. */
8
+ export interface PairBlock {
9
+ readonly kind: string;
10
+ readonly keeper: Node;
11
+ readonly other: Node;
12
+ /** Fields both fill and that name one thing (an email, a code, a value they share): asked one by one. */
13
+ readonly keys: readonly string[];
14
+ /** Words a person reads: "both have the word “acme”". */
15
+ readonly evidence: readonly string[];
16
+ readonly strength: number;
17
+ }
18
+ /** A far record a relation might point to, and why it was put forward. */
19
+ export interface TargetBlock {
20
+ readonly node: Node;
21
+ /** "its notes say “Harbor Catering”", "they share the word “harbor”", "the host's search calls it near". */
22
+ readonly evidence: string;
23
+ /** Whether the record's own text names it. */
24
+ readonly mentioned: boolean;
25
+ }
26
+ /** One relation of a record to ask about: the act that links it, and the far records to choose among. */
27
+ export interface LinkBlock {
28
+ readonly relation: string;
29
+ readonly description?: string;
30
+ /** An empty one-link relation (`missing-links`), rather than a link the record's text names (`links`). */
31
+ readonly missing: boolean;
32
+ readonly act: {
33
+ readonly name: string;
34
+ readonly to: string;
35
+ };
36
+ readonly targets: readonly TargetBlock[];
37
+ }
38
+ /** One empty choice field of a record, and the act that writes it. */
39
+ export interface FillBlock {
40
+ readonly field: string;
41
+ readonly options: readonly string[];
42
+ readonly description?: string;
43
+ readonly writes: {
44
+ readonly mutation: string;
45
+ readonly arg: string;
46
+ readonly subjectArg: string;
47
+ };
48
+ }
49
+ /** Everything one record is asked about, in one request. */
50
+ export interface RecordBlock {
51
+ readonly node: Node;
52
+ /** Present when it is old enough to set aside: how many days unchanged, and what its declaration says of it. */
53
+ readonly archive?: {
54
+ readonly days: number;
55
+ readonly why?: string;
56
+ };
57
+ readonly fills: readonly FillBlock[];
58
+ readonly links: readonly LinkBlock[];
59
+ }
60
+ export interface Blocks {
61
+ readonly pairs: readonly PairBlock[];
62
+ readonly records: readonly RecordBlock[];
63
+ }
64
+ /** What blocking may find, and how much of it. */
65
+ export interface BlockingOptions {
66
+ /** The judges' names a run uses: only their families are found. */
67
+ readonly families: ReadonlySet<string>;
68
+ /** The host's ranker (`HostAi.near`): records it calls near are paired too. */
69
+ readonly near?: SearchRanker;
70
+ /** At most this many pairs a run. 40 when unsaid. */
71
+ readonly maxPairs?: number;
72
+ /** At most this many records a run. 60 when unsaid. */
73
+ readonly maxRecords?: number;
74
+ /** At most this many far records a relation chooses among. 8 when unsaid. */
75
+ readonly maxTargets?: number;
76
+ }
77
+ /** A text's telling words: folded, three letters or more, the stop words out. */
78
+ export declare function wordsOf(text: string): string[];
79
+ /** What a run would ask a model about: pairs that may be one, and records with something to judge. */
80
+ export declare function blocksOf(context: JudgeContext, options: BlockingOptions): Promise<Blocks>;
81
+ export {};
82
+ //# sourceMappingURL=blocking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocking.d.ts","sourceRoot":"","sources":["../../src/tidy/blocking.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0C,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAK1F,OAAO,EAA8F,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAa5I,KAAK,IAAI,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAErF,0HAA0H;AAC1H,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,yGAAyG;IACzG,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,0EAA0E;AAC1E,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,4GAA4G;IAC5G,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,8CAA8C;IAC9C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED,yGAAyG;AACzG,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,0GAA0G;IAC1G,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;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,CAAC;IAC7B,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,uDAAuD;IACvD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAOD,iFAAiF;AACjF,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAI9C;AAiOD,sGAAsG;AACtG,wBAAsB,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAK/F"}
@@ -0,0 +1,260 @@
1
+ import { humanizeField, nameKey } from "@graview/core";
2
+ import { formFields } from "@graview/core/forms";
3
+ import { fold } from "@graview/core/search";
4
+ import { tidyingOf } from "@graview/core/tidying";
5
+ import { questionsForKind } from "../questions.js";
6
+ import { actNamed, connectOf, fieldsOf, finishedOf, KEY_FIELD, keeperOf, lastMoved, mayTouch, named } from "./judges.js";
7
+ /** Words that say nothing about which thing it is: articles, joins, a company's legal form. */
8
+ const STOP = new Set("the and for with from into onto about this that these those your our their its are was were has have had not but all any can will per via inc incorporated corp corporation company llc ltd limited group plc gmbh".split(" "));
9
+ /** A text's telling words: folded, three letters or more, the stop words out. */
10
+ export function wordsOf(text) {
11
+ return fold(text)
12
+ .split(" ")
13
+ .filter((word) => word.length >= 3 && !STOP.has(word));
14
+ }
15
+ /** Whether `inside` holds `words` as whole words, folded. */
16
+ const holds = (inside, words) => words.length > 0 && ` ${inside} `.includes(` ${words} `);
17
+ /** A record's own text, field by field: its string fields the declaration does not hide. */
18
+ function textsOf(schema, node) {
19
+ const hidden = new Set(schema.tryDefinition(node.kind)?.display?.hide ?? []);
20
+ return fieldsOf(schema, node.kind).flatMap((field) => {
21
+ const value = node[field];
22
+ return !hidden.has(field) && typeof value === "string" && value.trim() ? [{ field, text: value }] : [];
23
+ });
24
+ }
25
+ /** A kind's free-text fields: not a choice, a date or a number, whose shared value says nothing of which record it is. */
26
+ const freeText = (schema, kind) => {
27
+ const definition = schema.tryDefinition(kind);
28
+ return new Set(definition ? formFields(definition.fields).filter((field) => field.control === "text" && !("long" in field && field.long) && !("markdown" in field && field.markdown)).map((field) => field.name) : []);
29
+ };
30
+ /** The fields a short value of which names one thing — an email, a phone, a code: free text, not the label, not prose. */
31
+ const valueFields = (schema, node, label, free) => textsOf(schema, node).filter(({ field, text }) => free.has(field) && field !== label && text.length <= 80 && nameKey(text).length >= 3 && nameKey(text) !== nameKey(named(schema, node)));
32
+ /** The field a kind is named by, when it is one field: `label`, else `name` or `title`. */
33
+ const labelField = (schema, kind) => ["label", "name", "title"].find((field) => fieldsOf(schema, kind).includes(field));
34
+ /** Same-kind pairs that may be one record. */
35
+ async function pairsOf(context, options) {
36
+ const { store } = context;
37
+ const schema = store.schema;
38
+ const found = [];
39
+ for (const definition of schema.definitions) {
40
+ const kind = definition.kind;
41
+ if (definition.archives === false || !actNamed(store, `merge-${kind}`) || tidyingOf(schema, kind) === "never")
42
+ continue;
43
+ const records = store.graph.nodesOfKind(kind).filter((node) => mayTouch(context, node));
44
+ if (records.length < 2)
45
+ continue;
46
+ const label = labelField(schema, kind);
47
+ const byPair = new Map();
48
+ const pair = (a, b, strength, evidence, key) => {
49
+ if (a.id === b.id)
50
+ return;
51
+ const [first, second] = a.id < b.id ? [a, b] : [b, a];
52
+ const id = `${first.id}\u0000${second.id}`;
53
+ const was = byPair.get(id) ?? { a: first, b: second, strength: 0, evidence: [], keys: new Set() };
54
+ was.strength += strength;
55
+ if (!was.evidence.includes(evidence))
56
+ was.evidence.push(evidence);
57
+ if (key)
58
+ was.keys.add(key);
59
+ byPair.set(id, was);
60
+ };
61
+ // Telling words in the name and the key fields; a word half the kind shares tells nothing.
62
+ const index = new Map();
63
+ const wordSets = new Map();
64
+ for (const node of records) {
65
+ // A key value (an email, a code) is one word, whole: its domain alone says nothing.
66
+ const keys = fieldsOf(schema, kind).filter((field) => KEY_FIELD.test(field) && typeof node[field] === "string" && String(node[field]).trim()).map((field) => nameKey(String(node[field])));
67
+ const words = new Set([...wordsOf(named(schema, node)), ...keys]);
68
+ wordSets.set(node.id, words);
69
+ for (const word of words)
70
+ index.set(word, [...(index.get(word) ?? []), node]);
71
+ }
72
+ const common = Math.max(4, Math.ceil(records.length * 0.25));
73
+ for (const [word, holders] of index) {
74
+ if (holders.length < 2 || holders.length > common)
75
+ continue;
76
+ for (let i = 0; i < holders.length; i++)
77
+ for (let j = i + 1; j < holders.length; j++) {
78
+ const a = wordSets.get(holders[i].id);
79
+ const b = wordSets.get(holders[j].id);
80
+ const shared = [...a].filter((one) => b.has(one)).length;
81
+ // Each shared word adds 1 / the words between them, so a pair sums to its Jaccard.
82
+ pair(holders[i], holders[j], 1 / (a.size + b.size - shared), `both have the word “${word}”`);
83
+ }
84
+ }
85
+ // A short value both hold: an email, a phone, a website, a code.
86
+ const byValue = new Map();
87
+ const free = freeText(schema, kind);
88
+ for (const node of records)
89
+ for (const { field, text } of valueFields(schema, node, label, free)) {
90
+ const key = `${field}\u0000${nameKey(text)}`;
91
+ const was = byValue.get(key) ?? { field, nodes: [] };
92
+ was.nodes.push(node);
93
+ byValue.set(key, was);
94
+ }
95
+ for (const { field, nodes } of byValue.values()) {
96
+ if (nodes.length < 2 || nodes.length > common)
97
+ continue;
98
+ for (let i = 0; i < nodes.length; i++)
99
+ for (let j = i + 1; j < nodes.length; j++)
100
+ pair(nodes[i], nodes[j], 1, `both have the same ${field}`, field);
101
+ }
102
+ // The host's ranker, asked of each record's name over the rest of its kind.
103
+ if (options.near) {
104
+ for (const node of records.slice(0, 50)) {
105
+ const others = records.filter((one) => one.id !== node.id).map((one) => ({ id: one.id, kind, label: named(schema, one), texts: textsOf(schema, one).map(({ field, text }) => ({ field, reading: field, text })) }));
106
+ let scores = [];
107
+ try {
108
+ scores = await options.near(named(schema, node), others);
109
+ }
110
+ catch {
111
+ scores = [];
112
+ }
113
+ for (const score of scores) {
114
+ const other = records.find((one) => one.id === score.id);
115
+ if (other && score.score >= 0.5)
116
+ pair(node, other, score.score, "the host's search calls them near");
117
+ }
118
+ }
119
+ }
120
+ for (const { a, b, strength, evidence, keys } of byPair.values()) {
121
+ const keeper = keeperOf(store, [a, b], context.touched);
122
+ const other = keeper.id === a.id ? b : a;
123
+ const keyFields = new Set([...keys, ...fieldsOf(schema, kind).filter((field) => KEY_FIELD.test(field) && typeof a[field] === "string" && typeof b[field] === "string" && String(a[field]).trim() && String(b[field]).trim())]);
124
+ if (label)
125
+ keyFields.delete(label);
126
+ found.push({ kind, keeper, other, keys: [...keyFields], evidence, strength });
127
+ }
128
+ }
129
+ return found.sort((a, b) => b.strength - a.strength).slice(0, options.maxPairs ?? 40);
130
+ }
131
+ /** The far records a record might link to through one relation, likeliest first. */
132
+ async function targetsOf(context, node, targets, missing, options) {
133
+ const schema = context.store.schema;
134
+ const texts = textsOf(schema, node);
135
+ const own = fold(named(schema, node));
136
+ const said = texts.map(({ field, text }) => ({ field, text: fold(text) }));
137
+ const ownWords = new Set(wordsOf(texts.map(({ text }) => text).join(" ")));
138
+ const out = new Map();
139
+ const put = (far, evidence, weight, mentioned) => {
140
+ const was = out.get(far.id);
141
+ if (!was || was.weight < weight)
142
+ out.set(far.id, { node: far, evidence, weight, mentioned });
143
+ };
144
+ for (const far of targets) {
145
+ const name = fold(named(schema, far));
146
+ if (name.replace(/ /g, "").length < 3 || name === own)
147
+ continue;
148
+ // Its whole name in the record's text.
149
+ const whole = said.find(({ text }) => holds(text, name));
150
+ if (whole) {
151
+ put(far, `its ${humanizeField(whole.field).toLowerCase()} says “${named(schema, far)}”`, 3, true);
152
+ continue;
153
+ }
154
+ // One of its telling words, or one of its key values, in the record's text.
155
+ const aliases = [...wordsOf(named(schema, far)).filter((word) => word.length >= 4), ...fieldsOf(schema, far.kind).filter((field) => KEY_FIELD.test(field) && typeof far[field] === "string").map((field) => fold(String(far[field])))];
156
+ const alias = aliases.find((word) => said.some(({ text }) => holds(text, word)));
157
+ if (alias) {
158
+ put(far, `its text says “${alias}”`, 2, true);
159
+ continue;
160
+ }
161
+ if (!missing)
162
+ continue;
163
+ // For an empty one-link relation, a word or a value the two share is enough to ask.
164
+ const farWords = wordsOf([named(schema, far), ...textsOf(schema, far).map(({ text }) => text)].join(" "));
165
+ const shared = farWords.find((word) => ownWords.has(word));
166
+ if (shared)
167
+ put(far, `they share the word “${shared}”`, 1, false);
168
+ }
169
+ if (missing && options.near && out.size < (options.maxTargets ?? 8)) {
170
+ try {
171
+ const scores = await options.near(named(schema, node), targets.map((far) => ({ id: far.id, kind: far.kind, label: named(schema, far), texts: textsOf(schema, far).map(({ field, text }) => ({ field, reading: field, text })) })));
172
+ for (const score of scores) {
173
+ const far = targets.find((one) => one.id === score.id);
174
+ if (far && score.score >= 0.5)
175
+ put(far, "the host's search calls it near", score.score, false);
176
+ }
177
+ }
178
+ catch {
179
+ // A ranker that fails puts nothing forward.
180
+ }
181
+ }
182
+ return [...out.values()].sort((a, b) => b.weight - a.weight).slice(0, options.maxTargets ?? 8).map(({ node: far, evidence, mentioned }) => ({ node: far, evidence, mentioned }));
183
+ }
184
+ /** What each record is asked about: set aside, an empty choice, a link its text names, an empty one-link relation. */
185
+ async function recordsOf(context, options) {
186
+ const { store } = context;
187
+ const schema = store.schema;
188
+ const today = new Date(context.now).toISOString().slice(0, 10);
189
+ const wants = (family) => options.families.has(family);
190
+ const found = [];
191
+ for (const definition of schema.definitions) {
192
+ const kind = definition.kind;
193
+ if (tidyingOf(schema, kind) === "never")
194
+ continue;
195
+ const archives = wants("archive") && definition.archives !== false && actNamed(store, `archive-${kind}`) !== undefined;
196
+ const finished = archives ? finishedOf(schema, kind, today) : undefined;
197
+ const choices = wants("categorize")
198
+ ? questionsForKind(store, kind).flatMap((question) => {
199
+ if (question.about !== "field" || !question.writes || question.question.type !== "choice")
200
+ return [];
201
+ const field = formFields(definition.fields).find((one) => one.name === question.field);
202
+ return field?.control === "choice" && field.optional && field.options?.length ? [{ field: field.name, options: field.options, writes: question.writes, instructions: question.question.instructions }] : [];
203
+ })
204
+ : [];
205
+ const relations = Object.entries(definition.edges ?? {}).flatMap(([relation, edge]) => {
206
+ if (edge.acts === "none" || tidyingOf(schema, kind) === "no-links" || tidyingOf(schema, kind, relation) === "never")
207
+ return [];
208
+ const kinds = (edge.to === "*" ? schema.definitions.map((one) => one.kind) : edge.to).filter((target) => tidyingOf(schema, target) !== "never" && tidyingOf(schema, target) !== "no-links");
209
+ const act = connectOf(store, kind, relation, kinds);
210
+ return act ? [{ relation, edge, kinds, act }] : [];
211
+ });
212
+ for (const node of store.graph.nodesOfKind(kind)) {
213
+ if (!mayTouch(context, node))
214
+ continue;
215
+ let archive;
216
+ if (archives) {
217
+ const moved = lastMoved(schema, node, context.touched);
218
+ const days = moved === undefined ? -1 : Math.floor((context.now - moved) / 86_400_000);
219
+ if (days >= context.olderThanDays) {
220
+ const why = finished?.(node);
221
+ archive = { days, ...(why ? { why } : {}) };
222
+ }
223
+ }
224
+ const fills = choices.filter(({ field }) => node[field] === undefined || node[field] === null || node[field] === "").map(({ field, options: values, writes }) => {
225
+ const description = definition.fields.shape?.[field]?.description;
226
+ return { field, options: values, writes, ...(description ? { description } : {}) };
227
+ });
228
+ const links = [];
229
+ for (const { relation, edge, kinds, act } of relations) {
230
+ const linked = new Set(store.graph.out(node.id, relation).map((one) => one.id));
231
+ const missing = edge.cardinality === "one";
232
+ if (missing && linked.size > 0)
233
+ continue;
234
+ if (!wants(missing ? "missing-links" : "links"))
235
+ continue;
236
+ const pool = kinds.flatMap((target) => store.graph.nodesOfKind(target)).filter((far) => far.id !== node.id && !linked.has(far.id) && mayTouch(context, far));
237
+ const targets = await targetsOf(context, node, pool, missing, options);
238
+ if (targets.length > 0)
239
+ links.push({ relation, ...(edge.description ? { description: edge.description } : {}), missing, act, targets });
240
+ }
241
+ if (!archive && fills.length === 0 && links.length === 0)
242
+ continue;
243
+ // A record its declaration says is finished, then one that names another, comes first.
244
+ const weight = (archive?.why ? 3 : archive ? 1 : 0) + links.filter((link) => link.targets.some((target) => target.mentioned)).length * 2 + links.length + fills.length;
245
+ found.push({ node, ...(archive ? { archive } : {}), fills, links, weight });
246
+ }
247
+ }
248
+ return found
249
+ .sort((a, b) => b.weight - a.weight)
250
+ .slice(0, options.maxRecords ?? 60)
251
+ .map(({ weight: _weight, ...block }) => block);
252
+ }
253
+ /** What a run would ask a model about: pairs that may be one, and records with something to judge. */
254
+ export async function blocksOf(context, options) {
255
+ return {
256
+ pairs: options.families.has("duplicates") ? await pairsOf(context, options) : [],
257
+ records: await recordsOf(context, options),
258
+ };
259
+ }
260
+ //# sourceMappingURL=blocking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blocking.js","sourceRoot":"","sources":["../../src/tidy/blocking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAqC,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAqB,MAAM,aAAa,CAAC;AAkF5I,+FAA+F;AAC/F,MAAM,IAAI,GAAG,IAAI,GAAG,CAClB,oNAAoN,CAAC,KAAK,CAAC,GAAG,CAAC,CAChO,CAAC;AAEF,iFAAiF;AACjF,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,IAAI,CAAC,IAAI,CAAC;SACd,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,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C,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;QAChF,OAAO,EAAE,MAAM,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC;KAC3C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,117 @@
1
+ import { type AnySchema, type Author, type Store, type Via } from "@graview/core";
2
+ import type { HostAi } from "../ai.js";
3
+ import { type DreamBudget, type DreamCache, type DreamUsage } from "./asking.js";
4
+ import { type Candidate, type Judge } from "./judges.js";
5
+ import { type Band, type Severity } from "./policy.js";
6
+ import { type DreamModel } from "./system-one.js";
7
+ /** "Graview, tidying": the app's own actor, as a run is made by unless a host names its own. */
8
+ export declare const TIDYING_ACTOR: Author;
9
+ export interface DreamOptions {
10
+ /** Who runs: an author that says `automated: true`. `TIDYING_ACTOR` when unsaid; a person is refused. */
11
+ readonly principal?: Author;
12
+ /** The judges to run, in order. Every one (`JUDGES`) when unsaid; a model judges only these judges' families. */
13
+ readonly judges?: readonly Judge[];
14
+ /** The System One model that judges, when the host lends one directly. */
15
+ readonly model?: DreamModel;
16
+ /** The host's AI, as a seat is handed it: its Fast slot (or `decide`) judges, and its `near` ranker widens the pairs. Ignored when it says `off`. */
17
+ readonly ai?: HostAi;
18
+ /** How sure each severity must be to be made unasked, and to be asked at all (`BANDS` when unsaid). */
19
+ readonly bands?: Partial<Record<Severity, Partial<Band>>>;
20
+ /** Requests at once. 6 when unsaid. */
21
+ readonly concurrency?: number;
22
+ /** What a run may spend on the model: 60 requests and 200,000 input tokens when unsaid. */
23
+ readonly budget?: DreamBudget;
24
+ /** Where answers are kept between runs, by what was asked; one cache per process when unsaid, none with `false`. */
25
+ readonly cache?: DreamCache | false;
26
+ /** How much blocking puts forward: pairs (40), records (60), far records a relation chooses among (8). */
27
+ readonly blocking?: {
28
+ readonly maxPairs?: number;
29
+ readonly maxRecords?: number;
30
+ readonly maxTargets?: number;
31
+ };
32
+ /** The run's moment. Now when unsaid. */
33
+ readonly now?: Date | string | number;
34
+ /** At most this many changes suggested or applied in one run, surest first. 20 when unsaid. */
35
+ readonly limit?: number;
36
+ /** A record changed within this many hours is left for now. 24 when unsaid. */
37
+ readonly quietHours?: number;
38
+ /** A record is a candidate to set aside after this many days unchanged. 30 when unsaid. */
39
+ readonly olderThanDays?: number;
40
+ /**
41
+ * THE HOST LETS THE ACTOR APPLY what it is at least this sure of (0 to 1)
42
+ * — and only what its severity's band says may be made unasked — with its
43
+ * lineage, where the declaration and what people said allow it; the store
44
+ * still refuses what they do not. Unsaid, nothing is applied: everything
45
+ * sure enough is suggested.
46
+ */
47
+ readonly applyAtLeast?: number;
48
+ /** What its changes come through, as the log records it. */
49
+ readonly via?: Via;
50
+ }
51
+ /** What became of one judgment. */
52
+ export interface DreamOutcome {
53
+ readonly judge: string;
54
+ /**
55
+ * suggested: waits for a person; applied: made, with lineage; dropped: not
56
+ * sure enough to ask, or the model chose none; waiting: already
57
+ * suggested; declined: a person said no before; refused: the store said
58
+ * no, in `error`.
59
+ */
60
+ readonly outcome: "suggested" | "applied" | "dropped" | "waiting" | "declined" | "refused";
61
+ readonly calls: Candidate["calls"];
62
+ readonly basis: string;
63
+ readonly confidence: number;
64
+ readonly about: readonly string[];
65
+ /** The model that judged it; absent when the judges' own rules did. */
66
+ readonly model?: string;
67
+ /** The op that holds a suggestion, or the batch that applied a change. */
68
+ readonly id?: string;
69
+ readonly error?: string;
70
+ }
71
+ /** What a run did, by judge, and in a sentence. */
72
+ export interface DreamReport {
73
+ /**
74
+ * The run, by its moment: on every change and suggestion it made, as
75
+ * `lineage.run`, so Activity reads a night's work as one.
76
+ */
77
+ readonly run: string;
78
+ readonly outcomes: readonly DreamOutcome[];
79
+ readonly byJudge: Readonly<Record<string, {
80
+ readonly suggested: number;
81
+ readonly applied: number;
82
+ readonly skipped: number;
83
+ }>>;
84
+ /**
85
+ * The model asked: how many requests it was put, how many it answered,
86
+ * and its failure when it failed — what it did not answer was judged by
87
+ * the judges' own rules.
88
+ */
89
+ readonly model?: {
90
+ readonly name: string;
91
+ readonly answered: boolean;
92
+ readonly asks: number;
93
+ readonly judged: number;
94
+ readonly error?: string;
95
+ };
96
+ /** What asking the model spent. */
97
+ readonly usage?: DreamUsage;
98
+ /** Said when the run's budget stopped the asking. */
99
+ readonly budget?: string;
100
+ /** Why nothing was applied, when nothing could be. */
101
+ readonly applying: string;
102
+ /** "Suggested 3 changes and applied 1." */
103
+ readonly said: string;
104
+ }
105
+ /** When each record was last changed, from the log. */
106
+ export declare function touchedIn(store: Pick<Store<AnySchema>, "log">): Map<string, number>;
107
+ /**
108
+ * RUN THE APP'S OWN ACTOR ONCE. Blocking and a model, when lent, judge
109
+ * the store as the actor sees it; the judges' rules judge what the model
110
+ * did not; each judgment is routed by its confidence and severity, surest
111
+ * first up to `limit`. A change a person declined is never asked again;
112
+ * one already waiting is not asked twice; whatever the store refuses is
113
+ * reported, not thrown. Call it on the store that keeps the log — a
114
+ * server's, for a hosted app.
115
+ */
116
+ export declare function dream<S extends AnySchema>(store: Store<S>, options?: DreamOptions): Promise<DreamReport>;
117
+ //# sourceMappingURL=dream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dream.d.ts","sourceRoot":"","sources":["../../src/tidy/dream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,KAAK,KAAK,EAAE,KAAK,GAAG,EAAE,MAAM,eAAe,CAAC;AAE/F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzF,OAAO,EAAU,KAAK,SAAS,EAAE,KAAK,KAAK,EAAqB,MAAM,aAAa,CAAC;AACpF,OAAO,EAAW,KAAK,IAAI,EAAc,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5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