@wirecat/files-cli 0.1.0 → 0.3.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.
- package/CHANGELOG.md +43 -0
- package/README.md +2 -2
- package/contracts/wirecat.json +42 -0
- package/dist/bin/files.js +2 -2
- package/dist/bundle/{chunk-GNDPV4HK.js → chunk-AQW3A7LB.js} +1 -1
- package/dist/bundle/files.js +2 -2
- package/dist/bundle/{program-EN7Z757N.js → program-O44TKRRN.js} +528 -320
- package/dist/config.js +10 -1
- package/dist/doctor.js +33 -0
- package/dist/entities.js +1 -0
- package/dist/import/readers.js +10 -3
- package/dist/notes/bound.js +7 -5
- package/dist/notes/command.js +30 -3
- package/dist/notes/files.js +6 -0
- package/dist/notes/folders.js +6 -4
- package/dist/notes/import.js +67 -12
- package/dist/notes/links.js +3 -1
- package/dist/options.js +6 -0
- package/dist/people/command.js +92 -0
- package/dist/program.js +4 -1
- package/dist/sources/command.js +1 -8
- package/dist/sources/read.js +2 -1
- package/dist/sync.js +35 -9
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/skills/files-cli/SKILL.md +1 -1
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
__name,
|
|
9
9
|
__require,
|
|
10
10
|
__toESM
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-AQW3A7LB.js";
|
|
12
12
|
|
|
13
13
|
// node_modules/.pnpm/yaml@2.9.1/node_modules/yaml/dist/nodes/identity.js
|
|
14
14
|
var require_identity = __commonJS({
|
|
@@ -4083,10 +4083,10 @@ var require_resolve_block_map = __commonJS({
|
|
|
4083
4083
|
let offset = bm.offset;
|
|
4084
4084
|
let commentEnd = null;
|
|
4085
4085
|
for (const collItem of bm.items) {
|
|
4086
|
-
const { start, key, sep:
|
|
4086
|
+
const { start, key, sep: sep7, value } = collItem;
|
|
4087
4087
|
const keyProps = resolveProps.resolveProps(start, {
|
|
4088
4088
|
indicator: "explicit-key-ind",
|
|
4089
|
-
next: key ??
|
|
4089
|
+
next: key ?? sep7?.[0],
|
|
4090
4090
|
offset,
|
|
4091
4091
|
onError,
|
|
4092
4092
|
parentIndent: bm.indent,
|
|
@@ -4100,7 +4100,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
4100
4100
|
else if ("indent" in key && key.indent !== bm.indent)
|
|
4101
4101
|
onError(offset, "BAD_INDENT", startColMsg);
|
|
4102
4102
|
}
|
|
4103
|
-
if (!keyProps.anchor && !keyProps.tag && !
|
|
4103
|
+
if (!keyProps.anchor && !keyProps.tag && !sep7) {
|
|
4104
4104
|
commentEnd = keyProps.end;
|
|
4105
4105
|
if (keyProps.comment) {
|
|
4106
4106
|
if (map.comment)
|
|
@@ -4124,7 +4124,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
4124
4124
|
ctx.atKey = false;
|
|
4125
4125
|
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
4126
4126
|
onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
|
|
4127
|
-
const valueProps = resolveProps.resolveProps(
|
|
4127
|
+
const valueProps = resolveProps.resolveProps(sep7 ?? [], {
|
|
4128
4128
|
indicator: "map-value-ind",
|
|
4129
4129
|
next: value,
|
|
4130
4130
|
offset: keyNode.range[2],
|
|
@@ -4140,7 +4140,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
4140
4140
|
if (ctx.options.strict && keyProps.start < valueProps.found.offset - 1024)
|
|
4141
4141
|
onError(keyNode.range, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit block mapping key");
|
|
4142
4142
|
}
|
|
4143
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset,
|
|
4143
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset, sep7, null, valueProps, onError);
|
|
4144
4144
|
if (ctx.schema.compat)
|
|
4145
4145
|
utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
|
|
4146
4146
|
offset = valueNode.range[2];
|
|
@@ -4233,7 +4233,7 @@ var require_resolve_end = __commonJS({
|
|
|
4233
4233
|
let comment = "";
|
|
4234
4234
|
if (end) {
|
|
4235
4235
|
let hasSpace = false;
|
|
4236
|
-
let
|
|
4236
|
+
let sep7 = "";
|
|
4237
4237
|
for (const token of end) {
|
|
4238
4238
|
const { source, type } = token;
|
|
4239
4239
|
switch (type) {
|
|
@@ -4247,13 +4247,13 @@ var require_resolve_end = __commonJS({
|
|
|
4247
4247
|
if (!comment)
|
|
4248
4248
|
comment = cb;
|
|
4249
4249
|
else
|
|
4250
|
-
comment +=
|
|
4251
|
-
|
|
4250
|
+
comment += sep7 + cb;
|
|
4251
|
+
sep7 = "";
|
|
4252
4252
|
break;
|
|
4253
4253
|
}
|
|
4254
4254
|
case "newline":
|
|
4255
4255
|
if (comment)
|
|
4256
|
-
|
|
4256
|
+
sep7 += source;
|
|
4257
4257
|
hasSpace = true;
|
|
4258
4258
|
break;
|
|
4259
4259
|
default:
|
|
@@ -4297,18 +4297,18 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4297
4297
|
let offset = fc.offset + fc.start.source.length;
|
|
4298
4298
|
for (let i = 0; i < fc.items.length; ++i) {
|
|
4299
4299
|
const collItem = fc.items[i];
|
|
4300
|
-
const { start, key, sep:
|
|
4300
|
+
const { start, key, sep: sep7, value } = collItem;
|
|
4301
4301
|
const props = resolveProps.resolveProps(start, {
|
|
4302
4302
|
flow: fcName,
|
|
4303
4303
|
indicator: "explicit-key-ind",
|
|
4304
|
-
next: key ??
|
|
4304
|
+
next: key ?? sep7?.[0],
|
|
4305
4305
|
offset,
|
|
4306
4306
|
onError,
|
|
4307
4307
|
parentIndent: fc.indent,
|
|
4308
4308
|
startOnNewline: false
|
|
4309
4309
|
});
|
|
4310
4310
|
if (!props.found) {
|
|
4311
|
-
if (!props.anchor && !props.tag && !
|
|
4311
|
+
if (!props.anchor && !props.tag && !sep7 && !value) {
|
|
4312
4312
|
if (i === 0 && props.comma)
|
|
4313
4313
|
onError(props.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${fcName}`);
|
|
4314
4314
|
else if (i < fc.items.length - 1)
|
|
@@ -4362,8 +4362,8 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4362
4362
|
}
|
|
4363
4363
|
}
|
|
4364
4364
|
}
|
|
4365
|
-
if (!isMap && !
|
|
4366
|
-
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end,
|
|
4365
|
+
if (!isMap && !sep7 && !props.found) {
|
|
4366
|
+
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, sep7, null, props, onError);
|
|
4367
4367
|
coll.items.push(valueNode);
|
|
4368
4368
|
offset = valueNode.range[2];
|
|
4369
4369
|
if (isBlock(value))
|
|
@@ -4375,7 +4375,7 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4375
4375
|
if (isBlock(key))
|
|
4376
4376
|
onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
4377
4377
|
ctx.atKey = false;
|
|
4378
|
-
const valueProps = resolveProps.resolveProps(
|
|
4378
|
+
const valueProps = resolveProps.resolveProps(sep7 ?? [], {
|
|
4379
4379
|
flow: fcName,
|
|
4380
4380
|
indicator: "map-value-ind",
|
|
4381
4381
|
next: value,
|
|
@@ -4386,8 +4386,8 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4386
4386
|
});
|
|
4387
4387
|
if (valueProps.found) {
|
|
4388
4388
|
if (!isMap && !props.found && ctx.options.strict) {
|
|
4389
|
-
if (
|
|
4390
|
-
for (const st of
|
|
4389
|
+
if (sep7)
|
|
4390
|
+
for (const st of sep7) {
|
|
4391
4391
|
if (st === valueProps.found)
|
|
4392
4392
|
break;
|
|
4393
4393
|
if (st.type === "newline") {
|
|
@@ -4404,7 +4404,7 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4404
4404
|
else
|
|
4405
4405
|
onError(valueProps.start, "MISSING_CHAR", `Missing , or : between ${fcName} items`);
|
|
4406
4406
|
}
|
|
4407
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end,
|
|
4407
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end, sep7, null, valueProps, onError) : null;
|
|
4408
4408
|
if (valueNode) {
|
|
4409
4409
|
if (isBlock(value))
|
|
4410
4410
|
onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
@@ -4587,7 +4587,7 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
4587
4587
|
chompStart = i + 1;
|
|
4588
4588
|
}
|
|
4589
4589
|
let value = "";
|
|
4590
|
-
let
|
|
4590
|
+
let sep7 = "";
|
|
4591
4591
|
let prevMoreIndented = false;
|
|
4592
4592
|
for (let i = 0; i < contentStart; ++i)
|
|
4593
4593
|
value += lines[i][0].slice(trimIndent) + "\n";
|
|
@@ -4604,24 +4604,24 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
4604
4604
|
indent = "";
|
|
4605
4605
|
}
|
|
4606
4606
|
if (type === Scalar.Scalar.BLOCK_LITERAL) {
|
|
4607
|
-
value +=
|
|
4608
|
-
|
|
4607
|
+
value += sep7 + indent.slice(trimIndent) + content;
|
|
4608
|
+
sep7 = "\n";
|
|
4609
4609
|
} else if (indent.length > trimIndent || content[0] === " ") {
|
|
4610
|
-
if (
|
|
4611
|
-
|
|
4612
|
-
else if (!prevMoreIndented &&
|
|
4613
|
-
|
|
4614
|
-
value +=
|
|
4615
|
-
|
|
4610
|
+
if (sep7 === " ")
|
|
4611
|
+
sep7 = "\n";
|
|
4612
|
+
else if (!prevMoreIndented && sep7 === "\n")
|
|
4613
|
+
sep7 = "\n\n";
|
|
4614
|
+
value += sep7 + indent.slice(trimIndent) + content;
|
|
4615
|
+
sep7 = "\n";
|
|
4616
4616
|
prevMoreIndented = true;
|
|
4617
4617
|
} else if (content === "") {
|
|
4618
|
-
if (
|
|
4618
|
+
if (sep7 === "\n")
|
|
4619
4619
|
value += "\n";
|
|
4620
4620
|
else
|
|
4621
|
-
|
|
4621
|
+
sep7 = "\n";
|
|
4622
4622
|
} else {
|
|
4623
|
-
value +=
|
|
4624
|
-
|
|
4623
|
+
value += sep7 + content;
|
|
4624
|
+
sep7 = " ";
|
|
4625
4625
|
prevMoreIndented = false;
|
|
4626
4626
|
}
|
|
4627
4627
|
}
|
|
@@ -4810,25 +4810,25 @@ var require_resolve_flow_scalar = __commonJS({
|
|
|
4810
4810
|
trimBoth = /^[ \t]+|[ \t]+$/g;
|
|
4811
4811
|
}
|
|
4812
4812
|
let res = match[1].replace(trimEnd, "");
|
|
4813
|
-
let
|
|
4813
|
+
let sep7 = " ";
|
|
4814
4814
|
let pos = line2.lastIndex;
|
|
4815
4815
|
while (match = line2.exec(source)) {
|
|
4816
4816
|
const lm = match[1].replace(trimBoth, "");
|
|
4817
4817
|
if (lm === "") {
|
|
4818
|
-
if (
|
|
4819
|
-
res +=
|
|
4818
|
+
if (sep7 === "\n")
|
|
4819
|
+
res += sep7;
|
|
4820
4820
|
else
|
|
4821
|
-
|
|
4821
|
+
sep7 = "\n";
|
|
4822
4822
|
} else {
|
|
4823
|
-
res +=
|
|
4824
|
-
|
|
4823
|
+
res += sep7 + lm;
|
|
4824
|
+
sep7 = " ";
|
|
4825
4825
|
}
|
|
4826
4826
|
pos = line2.lastIndex;
|
|
4827
4827
|
}
|
|
4828
4828
|
const last = /[ \t]*(.*)/sy;
|
|
4829
4829
|
last.lastIndex = pos;
|
|
4830
4830
|
match = last.exec(source);
|
|
4831
|
-
return res +
|
|
4831
|
+
return res + sep7 + (match?.[1] ?? "");
|
|
4832
4832
|
}
|
|
4833
4833
|
__name(unfoldLines, "unfoldLines");
|
|
4834
4834
|
function doubleQuotedValue(source, onError) {
|
|
@@ -5662,14 +5662,14 @@ var require_cst_stringify = __commonJS({
|
|
|
5662
5662
|
}
|
|
5663
5663
|
}
|
|
5664
5664
|
__name(stringifyToken, "stringifyToken");
|
|
5665
|
-
function stringifyItem({ start, key, sep:
|
|
5665
|
+
function stringifyItem({ start, key, sep: sep7, value }) {
|
|
5666
5666
|
let res = "";
|
|
5667
5667
|
for (const st of start)
|
|
5668
5668
|
res += st.source;
|
|
5669
5669
|
if (key)
|
|
5670
5670
|
res += stringifyToken(key);
|
|
5671
|
-
if (
|
|
5672
|
-
for (const st of
|
|
5671
|
+
if (sep7)
|
|
5672
|
+
for (const st of sep7)
|
|
5673
5673
|
res += st.source;
|
|
5674
5674
|
if (value)
|
|
5675
5675
|
res += stringifyToken(value);
|
|
@@ -6858,18 +6858,18 @@ var require_parser = __commonJS({
|
|
|
6858
6858
|
if (this.type === "map-value-ind") {
|
|
6859
6859
|
const prev = getPrevProps(this.peek(2));
|
|
6860
6860
|
const start = getFirstKeyStartProps(prev);
|
|
6861
|
-
let
|
|
6861
|
+
let sep7;
|
|
6862
6862
|
if (scalar.end) {
|
|
6863
|
-
|
|
6864
|
-
|
|
6863
|
+
sep7 = scalar.end;
|
|
6864
|
+
sep7.push(this.sourceToken);
|
|
6865
6865
|
delete scalar.end;
|
|
6866
6866
|
} else
|
|
6867
|
-
|
|
6867
|
+
sep7 = [this.sourceToken];
|
|
6868
6868
|
const map = {
|
|
6869
6869
|
type: "block-map",
|
|
6870
6870
|
offset: scalar.offset,
|
|
6871
6871
|
indent: scalar.indent,
|
|
6872
|
-
items: [{ start, key: scalar, sep:
|
|
6872
|
+
items: [{ start, key: scalar, sep: sep7 }]
|
|
6873
6873
|
};
|
|
6874
6874
|
this.onKeyLine = true;
|
|
6875
6875
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -7022,15 +7022,15 @@ var require_parser = __commonJS({
|
|
|
7022
7022
|
} else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
|
|
7023
7023
|
const start2 = getFirstKeyStartProps(it.start);
|
|
7024
7024
|
const key = it.key;
|
|
7025
|
-
const
|
|
7026
|
-
|
|
7025
|
+
const sep7 = it.sep;
|
|
7026
|
+
sep7.push(this.sourceToken);
|
|
7027
7027
|
delete it.key;
|
|
7028
7028
|
delete it.sep;
|
|
7029
7029
|
this.stack.push({
|
|
7030
7030
|
type: "block-map",
|
|
7031
7031
|
offset: this.offset,
|
|
7032
7032
|
indent: this.indent,
|
|
7033
|
-
items: [{ start: start2, key, sep:
|
|
7033
|
+
items: [{ start: start2, key, sep: sep7 }]
|
|
7034
7034
|
});
|
|
7035
7035
|
} else if (start.length > 0) {
|
|
7036
7036
|
it.sep = it.sep.concat(start, this.sourceToken);
|
|
@@ -7224,13 +7224,13 @@ var require_parser = __commonJS({
|
|
|
7224
7224
|
const prev = getPrevProps(parent);
|
|
7225
7225
|
const start = getFirstKeyStartProps(prev);
|
|
7226
7226
|
fixFlowSeqItems(fc);
|
|
7227
|
-
const
|
|
7228
|
-
|
|
7227
|
+
const sep7 = fc.end.splice(1, fc.end.length);
|
|
7228
|
+
sep7.push(this.sourceToken);
|
|
7229
7229
|
const map = {
|
|
7230
7230
|
type: "block-map",
|
|
7231
7231
|
offset: fc.offset,
|
|
7232
7232
|
indent: fc.indent,
|
|
7233
|
-
items: [{ start, key: fc, sep:
|
|
7233
|
+
items: [{ start, key: fc, sep: sep7 }]
|
|
7234
7234
|
};
|
|
7235
7235
|
this.onKeyLine = true;
|
|
7236
7236
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -7514,7 +7514,7 @@ var require_dist = __commonJS({
|
|
|
7514
7514
|
});
|
|
7515
7515
|
|
|
7516
7516
|
// dist/program.js
|
|
7517
|
-
import { join as
|
|
7517
|
+
import { join as join14 } from "node:path";
|
|
7518
7518
|
import { processStreams, resolvePaths as resolvePaths6 } from "@wirecat/cli-base";
|
|
7519
7519
|
import { appDoctorCommand, appMcpCommand, appUpdate, commandsCommand, configCommand, createProgram as createSharedProgram, outputFor as outputFor2, run as runShared, runsCommand, skillCommand, upgradeCommand } from "@wirecat/cli-core";
|
|
7520
7520
|
import { Command } from "commander";
|
|
@@ -7528,7 +7528,8 @@ var STORE_CLIENT = { command: APP.command, version: APP.version };
|
|
|
7528
7528
|
|
|
7529
7529
|
// dist/config.js
|
|
7530
7530
|
import { CliError, configFilePath, resolvePaths, saveConfigFile } from "@wirecat/cli-base";
|
|
7531
|
-
import { commandPermissions, DEFAULT_DECISION_POLICY, issueMessage, onThisComputer, readConfigFile, settingsFor } from "@wirecat/cli-core";
|
|
7531
|
+
import { baseContext, commandPermissions, DEFAULT_DECISION_POLICY, fromFile, issueMessage, onThisComputer, readConfigFile, settingsFor } from "@wirecat/cli-core";
|
|
7532
|
+
import { DOCUMENT_SCAN_SETTINGS } from "@wirecat/cli-core/documents";
|
|
7532
7533
|
|
|
7533
7534
|
// node_modules/.pnpm/valibot@1.5.0_typescript@7.0.2/node_modules/valibot/dist/index.mjs
|
|
7534
7535
|
var store$4;
|
|
@@ -8147,11 +8148,16 @@ var NOTE_EXTENSIONS = [
|
|
|
8147
8148
|
".ods",
|
|
8148
8149
|
".pptx",
|
|
8149
8150
|
".epub",
|
|
8151
|
+
".odp",
|
|
8150
8152
|
".doc",
|
|
8153
|
+
".rtf",
|
|
8154
|
+
// cli-core has no reader for it: listed so the sync names it as not read instead of passing it over.
|
|
8151
8155
|
".xls",
|
|
8152
8156
|
".html",
|
|
8153
8157
|
".htm"
|
|
8154
8158
|
];
|
|
8159
|
+
var PICTURE_EXTENSIONS = [".jpg", ".jpeg", ".png", ".webp"];
|
|
8160
|
+
var isPicturePath = /* @__PURE__ */ __name((path) => PICTURE_EXTENSIONS.some((extension) => path.toLowerCase().endsWith(extension)), "isPicturePath");
|
|
8155
8161
|
var MEMO_ID = /^---\r?\n(?:[^\n]*\n)*?memo-id:[ \t]*["']?([^"'\s]+)/;
|
|
8156
8162
|
var HEAD = 1024;
|
|
8157
8163
|
var readMemoId = /* @__PURE__ */ __name((path) => {
|
|
@@ -8379,8 +8385,14 @@ var OwnSchema = object({ notes: optional(NotesSchema), sources: optional(Sources
|
|
|
8379
8385
|
var permissions = commandPermissions();
|
|
8380
8386
|
var configuration = settingsFor(IDENTITY, {
|
|
8381
8387
|
permissions,
|
|
8382
|
-
defaults: { notes: optional(NotesSchema), sources: optional(SourcesSchema) }
|
|
8388
|
+
defaults: { notes: optional(NotesSchema), sources: optional(SourcesSchema) },
|
|
8389
|
+
profile: DOCUMENT_SCAN_SETTINGS.profile,
|
|
8390
|
+
settings: DOCUMENT_SCAN_SETTINGS.settings
|
|
8383
8391
|
});
|
|
8392
|
+
var readScans = /* @__PURE__ */ __name((command) => {
|
|
8393
|
+
const { settings } = baseContext(command, (flags, options) => configuration.resolveSettings(flags, { ...options, needsProfile: false }));
|
|
8394
|
+
return fromFile(settings, "read_scans", "local").value;
|
|
8395
|
+
}, "readScans");
|
|
8384
8396
|
var configPath = /* @__PURE__ */ __name((env = process.env) => configFilePath(resolvePaths({ appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env }).config), "configPath");
|
|
8385
8397
|
var rawConfig = /* @__PURE__ */ __name((env) => {
|
|
8386
8398
|
const read = readConfigFile(configPath(env));
|
|
@@ -8458,6 +8470,107 @@ var answers = /* @__PURE__ */ __name((program, _streams, env) => {
|
|
|
8458
8470
|
};
|
|
8459
8471
|
}, "answers");
|
|
8460
8472
|
|
|
8473
|
+
// dist/doctor.js
|
|
8474
|
+
import { existsSync } from "node:fs";
|
|
8475
|
+
|
|
8476
|
+
// dist/notes/folders.js
|
|
8477
|
+
import { realpathSync, statSync } from "node:fs";
|
|
8478
|
+
import { basename, dirname, join as join2, resolve, sep as sep2 } from "node:path";
|
|
8479
|
+
import { CliError as CliError2 } from "@wirecat/cli-base";
|
|
8480
|
+
var entryOf = /* @__PURE__ */ __name((entry) => typeof entry === "string" ? { id: null, path: resolve(entry), format: "obsidian" } : { id: entry.id, path: resolve(entry.path), format: entry.format ?? "obsidian" }, "entryOf");
|
|
8481
|
+
var noteFolders = /* @__PURE__ */ __name((notes) => (notes?.folders ?? []).map(entryOf), "noteFolders");
|
|
8482
|
+
var written = /* @__PURE__ */ __name((folder) => ({
|
|
8483
|
+
id: folder.id,
|
|
8484
|
+
path: folder.path,
|
|
8485
|
+
...folder.format === "obsidian" ? {} : { format: folder.format }
|
|
8486
|
+
}), "written");
|
|
8487
|
+
var withFolders = /* @__PURE__ */ __name((config, folders) => ({
|
|
8488
|
+
...config,
|
|
8489
|
+
notes: {
|
|
8490
|
+
...config.notes,
|
|
8491
|
+
folders: folders.map((folder) => folder.id === null ? folder.path : written(folder))
|
|
8492
|
+
}
|
|
8493
|
+
}), "withFolders");
|
|
8494
|
+
var bindFolder = /* @__PURE__ */ __name((config, folder) => {
|
|
8495
|
+
const at = resolve(folder.path);
|
|
8496
|
+
const folders = noteFolders(config.notes);
|
|
8497
|
+
const index = folders.findIndex((other) => other.path === at);
|
|
8498
|
+
const bound = { ...folder, path: at };
|
|
8499
|
+
const kept = folders.map((other, position) => position === index ? bound : other).filter((other, position) => position === index || other.id !== folder.id && other.path !== at);
|
|
8500
|
+
return withFolders(config, index < 0 ? [...kept, bound] : kept);
|
|
8501
|
+
}, "bindFolder");
|
|
8502
|
+
var attachFolder = /* @__PURE__ */ __name((config, id, path, format) => {
|
|
8503
|
+
const at = resolve(path);
|
|
8504
|
+
const folders = noteFolders(config.notes);
|
|
8505
|
+
const taken = folders.find((folder2) => folder2.path === at && folder2.id !== null && folder2.id !== id);
|
|
8506
|
+
if (taken)
|
|
8507
|
+
throw new CliError2("validation_error", `${at} is already folder ${taken.id} \u2014 attach that id elsewhere first, or remove it from the config`);
|
|
8508
|
+
const previous = folders.find((folder2) => folder2.id === id);
|
|
8509
|
+
const folder = { id, path: at, format: format ?? previous?.format ?? "obsidian" };
|
|
8510
|
+
const kept = folders.filter((other) => other.id !== id && other.path !== at);
|
|
8511
|
+
return { config: withFolders(config, [...kept, folder]), folder };
|
|
8512
|
+
}, "attachFolder");
|
|
8513
|
+
var unbindFolder = /* @__PURE__ */ __name((config, path) => withFolders(config, noteFolders(config.notes).filter((folder) => folder.path !== resolve(path))), "unbindFolder");
|
|
8514
|
+
var real = /* @__PURE__ */ __name((path) => {
|
|
8515
|
+
const at = resolve(path);
|
|
8516
|
+
try {
|
|
8517
|
+
return realpathSync(at);
|
|
8518
|
+
} catch {
|
|
8519
|
+
const parent = dirname(at);
|
|
8520
|
+
return parent === at ? at : join2(real(parent), basename(at));
|
|
8521
|
+
}
|
|
8522
|
+
}, "real");
|
|
8523
|
+
var detectFormat = /* @__PURE__ */ __name((path) => {
|
|
8524
|
+
for (let at = real(path); ; at = dirname(at)) {
|
|
8525
|
+
try {
|
|
8526
|
+
if (statSync(join2(at, ".obsidian")).isDirectory())
|
|
8527
|
+
return "obsidian";
|
|
8528
|
+
} catch {
|
|
8529
|
+
}
|
|
8530
|
+
if (dirname(at) === at)
|
|
8531
|
+
return "markdown";
|
|
8532
|
+
}
|
|
8533
|
+
}, "detectFormat");
|
|
8534
|
+
var comparable = /* @__PURE__ */ __name((path) => process.platform === "darwin" || process.platform === "win32" ? real(path).toLowerCase() : real(path), "comparable");
|
|
8535
|
+
var inside = /* @__PURE__ */ __name((child, parent) => child.startsWith(parent.endsWith(sep2) ? parent : `${parent}${sep2}`), "inside");
|
|
8536
|
+
var overlapping = /* @__PURE__ */ __name((folders, path) => {
|
|
8537
|
+
const at = comparable(path);
|
|
8538
|
+
return folders.filter((folder) => {
|
|
8539
|
+
const other = comparable(folder.path);
|
|
8540
|
+
return other !== at && (inside(at, other) || inside(other, at));
|
|
8541
|
+
});
|
|
8542
|
+
}, "overlapping");
|
|
8543
|
+
|
|
8544
|
+
// dist/doctor.js
|
|
8545
|
+
var notesFolderCheck = /* @__PURE__ */ __name((env) => {
|
|
8546
|
+
const configured = noteFolders(loadConfig(env).notes);
|
|
8547
|
+
const problems = [];
|
|
8548
|
+
for (const [index, folder] of configured.entries())
|
|
8549
|
+
for (const other of overlapping(configured.slice(index + 1), folder.path))
|
|
8550
|
+
problems.push({
|
|
8551
|
+
what: `the notes folders ${folder.path} and ${other.path} overlap, so the files they share are read twice`,
|
|
8552
|
+
fix: `files folders remove "${other.path}" (or the other one)`
|
|
8553
|
+
});
|
|
8554
|
+
const folders = configured.map(({ path, id }) => ({ path, exists: existsSync(path), bound: id !== null }));
|
|
8555
|
+
for (const folder of folders) {
|
|
8556
|
+
if (!folder.exists)
|
|
8557
|
+
problems.push({
|
|
8558
|
+
what: `the notes folder ${folder.path} is missing`,
|
|
8559
|
+
fix: "connect its disk; if it moved, files folders update <id> <new path>"
|
|
8560
|
+
});
|
|
8561
|
+
else if (!folder.bound)
|
|
8562
|
+
problems.push({
|
|
8563
|
+
what: `the notes folder ${folder.path} has no folder id`,
|
|
8564
|
+
fix: `files folders add "${folder.path}"`
|
|
8565
|
+
});
|
|
8566
|
+
}
|
|
8567
|
+
return {
|
|
8568
|
+
fields: { notes_folders: folders, problems },
|
|
8569
|
+
notes: problems.map(({ what, fix }) => `${what} \u2014 ${fix}`),
|
|
8570
|
+
failing: problems.length > 0
|
|
8571
|
+
};
|
|
8572
|
+
}, "notesFolderCheck");
|
|
8573
|
+
|
|
8461
8574
|
// dist/entities.js
|
|
8462
8575
|
import { metaOf } from "@wirecat/cli-base/commands";
|
|
8463
8576
|
import { answerEntity, answerFields } from "@wirecat/cli-core";
|
|
@@ -8494,6 +8607,7 @@ var OWN_FIELDS = {
|
|
|
8494
8607
|
"cut"
|
|
8495
8608
|
],
|
|
8496
8609
|
notes_folder: ["id", "name", "path", "format", "kept_by"],
|
|
8610
|
+
person_note_links: ["person", "name", "files"],
|
|
8497
8611
|
source_detail: [
|
|
8498
8612
|
"ref",
|
|
8499
8613
|
"title",
|
|
@@ -8557,7 +8671,7 @@ var declareOwnAnswers = /* @__PURE__ */ __name((command) => {
|
|
|
8557
8671
|
}, "declareOwnAnswers");
|
|
8558
8672
|
|
|
8559
8673
|
// dist/import/command.js
|
|
8560
|
-
import { CliError as
|
|
8674
|
+
import { CliError as CliError8 } from "@wirecat/cli-base";
|
|
8561
8675
|
import { annotate } from "@wirecat/cli-base/commands";
|
|
8562
8676
|
import { environmentOf as environmentOf2, ingestLines as ingestLines2, LOCAL_WRITE, providerNamed } from "@wirecat/cli-core";
|
|
8563
8677
|
|
|
@@ -8565,7 +8679,7 @@ import { environmentOf as environmentOf2, ingestLines as ingestLines2, LOCAL_WRI
|
|
|
8565
8679
|
import { openSync as openSync2 } from "node:fs";
|
|
8566
8680
|
import { createInterface } from "node:readline";
|
|
8567
8681
|
import { ReadStream } from "node:tty";
|
|
8568
|
-
import { CliError as
|
|
8682
|
+
import { CliError as CliError3 } from "@wirecat/cli-base";
|
|
8569
8683
|
import { environmentOf } from "@wirecat/cli-core";
|
|
8570
8684
|
|
|
8571
8685
|
// dist/terminal.js
|
|
@@ -8595,7 +8709,7 @@ var fromTerminal = /* @__PURE__ */ __name(async (question) => {
|
|
|
8595
8709
|
const reader2 = createInterface({ input, output: process.stderr, terminal: true });
|
|
8596
8710
|
try {
|
|
8597
8711
|
return await new Promise((resolve6, reject) => {
|
|
8598
|
-
const cancel = /* @__PURE__ */ __name(() => reject(new
|
|
8712
|
+
const cancel = /* @__PURE__ */ __name(() => reject(new CliError3("cancelled", "cancelled \u2014 nothing was done")), "cancel");
|
|
8599
8713
|
reader2.once("SIGINT", cancel);
|
|
8600
8714
|
reader2.once("close", cancel);
|
|
8601
8715
|
reader2.question(question, resolve6);
|
|
@@ -8615,15 +8729,15 @@ var ownerSays = /* @__PURE__ */ __name(async (command, question) => {
|
|
|
8615
8729
|
const machine = command.optsWithGlobals().json !== void 0;
|
|
8616
8730
|
const answer = terminalOf(command).present && !machine ? await (terminalOf(command).answer ?? environmentOf(command).answer ?? fromTerminal)(`${question} [y/N] `) : null;
|
|
8617
8731
|
if (answer === null)
|
|
8618
|
-
throw new
|
|
8732
|
+
throw new CliError3("confirmation_required", "--as-owner asks at a terminal, and nobody is at one to answer; the owner runs it there, without --json", { reason: "decision.owner-unconfirmed" });
|
|
8619
8733
|
if (!/^\s*y(es)?\s*$/i.test(answer))
|
|
8620
|
-
throw new
|
|
8734
|
+
throw new CliError3("cancelled", "not done \u2014 the answer was no");
|
|
8621
8735
|
}, "ownerSays");
|
|
8622
8736
|
var isMcpRun = /* @__PURE__ */ __name((command, _env) => environmentOf(command).agent !== void 0, "isMcpRun");
|
|
8623
8737
|
var whoRuns = /* @__PURE__ */ __name(async (command, env, { asOwner = false, question }) => {
|
|
8624
8738
|
if (isMcpRun(command, env)) {
|
|
8625
8739
|
if (asOwner)
|
|
8626
|
-
throw new
|
|
8740
|
+
throw new CliError3("permission_error", "an agent cannot act as the owner; the owner runs this command");
|
|
8627
8741
|
return { bot: agentIn(env) ?? "files-mcp" };
|
|
8628
8742
|
}
|
|
8629
8743
|
if (command.opts().fromApp)
|
|
@@ -8642,7 +8756,7 @@ var reasonOption = /* @__PURE__ */ __name((command) => command.option("--reason
|
|
|
8642
8756
|
|
|
8643
8757
|
// dist/records/input.js
|
|
8644
8758
|
import { open } from "node:fs/promises";
|
|
8645
|
-
import { CliError as
|
|
8759
|
+
import { CliError as CliError4 } from "@wirecat/cli-base";
|
|
8646
8760
|
import { envelopeOfText, ingest, ingestLines, ingestVcard, isVcard, jsonlLines } from "@wirecat/cli-core";
|
|
8647
8761
|
var PHONE = "phone";
|
|
8648
8762
|
var BOM = /^\uFEFF/;
|
|
@@ -8659,12 +8773,12 @@ var linesOf = /* @__PURE__ */ __name(async (file, stdin) => {
|
|
|
8659
8773
|
return jsonlLines(handle.createReadStream({ encoding: "utf8" }));
|
|
8660
8774
|
} catch (error) {
|
|
8661
8775
|
if (errnoOf(error) === "ENOENT")
|
|
8662
|
-
throw new
|
|
8776
|
+
throw new CliError4("not_found", `no records file ${file}: give a file that exists, or - for stdin`, {
|
|
8663
8777
|
reason: "records.file-missing",
|
|
8664
8778
|
path: file
|
|
8665
8779
|
});
|
|
8666
8780
|
const why = errnoOf(error) === "EISDIR" ? "it is a folder" : errnoOf(error) === "EACCES" ? "no permission" : "unreadable";
|
|
8667
|
-
throw new
|
|
8781
|
+
throw new CliError4("validation_error", `the records file ${file} cannot be read: ${why}`, {
|
|
8668
8782
|
reason: "records.file-unreadable",
|
|
8669
8783
|
path: file,
|
|
8670
8784
|
why
|
|
@@ -8688,7 +8802,7 @@ var deviceOf = /* @__PURE__ */ __name((given) => {
|
|
|
8688
8802
|
if (at < 0)
|
|
8689
8803
|
return given;
|
|
8690
8804
|
if (given.slice(0, at) !== PHONE)
|
|
8691
|
-
throw new
|
|
8805
|
+
throw new CliError4("validation_error", "a vCard file holds a phone's contacts: --account phone:<device>", {
|
|
8692
8806
|
param: "--account"
|
|
8693
8807
|
});
|
|
8694
8808
|
return given.slice(at + 1);
|
|
@@ -8761,19 +8875,19 @@ var receiptText = /* @__PURE__ */ __name((receipt) => [
|
|
|
8761
8875
|
].join("\n"), "receiptText");
|
|
8762
8876
|
|
|
8763
8877
|
// dist/records/source.js
|
|
8764
|
-
import { CliError as
|
|
8878
|
+
import { CliError as CliError5 } from "@wirecat/cli-base";
|
|
8765
8879
|
var sourceOf = /* @__PURE__ */ __name((account) => {
|
|
8766
8880
|
const [provider = "", ...rest] = (account ?? "").trim().split(":");
|
|
8767
8881
|
const name = rest.join(":");
|
|
8768
8882
|
if (!provider || !name)
|
|
8769
|
-
throw new
|
|
8883
|
+
throw new CliError5("validation_error", "name the source as --account <provider>:<account>, such as sheet:rentals", {
|
|
8770
8884
|
param: "--account"
|
|
8771
8885
|
});
|
|
8772
8886
|
return { provider, account: name };
|
|
8773
8887
|
}, "sourceOf");
|
|
8774
8888
|
|
|
8775
8889
|
// dist/import/audio.js
|
|
8776
|
-
import { CliError as
|
|
8890
|
+
import { CliError as CliError6, isCliError } from "@wirecat/cli-base";
|
|
8777
8891
|
import { DEFAULT_ORDER, decodeAudio, installedBytes, isInstalled, megabytes, modelsDirectory, recognizeLocalPieces, runFfmpeg, speechModel } from "@wirecat/cli-core";
|
|
8778
8892
|
|
|
8779
8893
|
// dist/import/external-id.js
|
|
@@ -8781,8 +8895,8 @@ import { createHash } from "node:crypto";
|
|
|
8781
8895
|
var MOST = 180;
|
|
8782
8896
|
var HASHED_HEAD = 160;
|
|
8783
8897
|
var PLAIN = /[A-Za-z0-9._-]/;
|
|
8784
|
-
var idOfPath = /* @__PURE__ */ __name((
|
|
8785
|
-
const normalized =
|
|
8898
|
+
var idOfPath = /* @__PURE__ */ __name((relative6) => {
|
|
8899
|
+
const normalized = relative6.split(/[\\/]/).join("/").normalize("NFC");
|
|
8786
8900
|
let id = "";
|
|
8787
8901
|
for (const char of normalized) {
|
|
8788
8902
|
if (PLAIN.test(char))
|
|
@@ -8801,7 +8915,7 @@ var idOfPath = /* @__PURE__ */ __name((relative5) => {
|
|
|
8801
8915
|
import { createHash as createHash2 } from "node:crypto";
|
|
8802
8916
|
import { constants } from "node:fs";
|
|
8803
8917
|
import { lstat, open as open2, readdir, realpath } from "node:fs/promises";
|
|
8804
|
-
import { basename, extname, join as
|
|
8918
|
+
import { basename as basename2, extname, join as join3, relative as relative2, sep as sep3 } from "node:path";
|
|
8805
8919
|
import { pathToFileURL } from "node:url";
|
|
8806
8920
|
import { attachmentMaxBytes, readWhole, sizeText } from "@wirecat/cli-core/documents";
|
|
8807
8921
|
var MOST_FILES = 1e4;
|
|
@@ -8834,7 +8948,7 @@ var unreadable = /* @__PURE__ */ __name((error) => {
|
|
|
8834
8948
|
return "it disappeared while the import ran";
|
|
8835
8949
|
return `could not be read${error instanceof Error ? `: ${error.message}` : ""}`;
|
|
8836
8950
|
}, "unreadable");
|
|
8837
|
-
var isInside = /* @__PURE__ */ __name((root, path) => path === root || path.startsWith(root +
|
|
8951
|
+
var isInside = /* @__PURE__ */ __name((root, path) => path === root || path.startsWith(root + sep3), "isInside");
|
|
8838
8952
|
var walk = /* @__PURE__ */ __name(async (root) => {
|
|
8839
8953
|
const real2 = await realpath(root);
|
|
8840
8954
|
const files = [];
|
|
@@ -8843,7 +8957,7 @@ var walk = /* @__PURE__ */ __name(async (root) => {
|
|
|
8843
8957
|
if (!stat.isDirectory()) {
|
|
8844
8958
|
if (!stat.isFile())
|
|
8845
8959
|
return { files, skipped: [{ path: root, reason: "not a file or a folder" }], base: real2 };
|
|
8846
|
-
const name =
|
|
8960
|
+
const name = basename2(real2);
|
|
8847
8961
|
return {
|
|
8848
8962
|
files: [{ path: real2, relative: name, extension: extname(name).toLowerCase(), stat }],
|
|
8849
8963
|
skipped,
|
|
@@ -8859,15 +8973,15 @@ var walk = /* @__PURE__ */ __name(async (root) => {
|
|
|
8859
8973
|
try {
|
|
8860
8974
|
entries = await readdir(folder, { withFileTypes: true });
|
|
8861
8975
|
} catch (error) {
|
|
8862
|
-
skipped.push({ path: relative2(real2, folder).split(
|
|
8976
|
+
skipped.push({ path: relative2(real2, folder).split(sep3).join("/") || ".", reason: unreadable(error) });
|
|
8863
8977
|
return;
|
|
8864
8978
|
}
|
|
8865
8979
|
entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
8866
8980
|
for (const entry of entries) {
|
|
8867
8981
|
if (entry.name.startsWith("."))
|
|
8868
8982
|
continue;
|
|
8869
|
-
const path =
|
|
8870
|
-
const shown = relative2(real2, path).split(
|
|
8983
|
+
const path = join3(folder, entry.name);
|
|
8984
|
+
const shown = relative2(real2, path).split(sep3).join("/");
|
|
8871
8985
|
if (entry.isSymbolicLink()) {
|
|
8872
8986
|
skipped.push({ path: shown, reason: refusedLink });
|
|
8873
8987
|
continue;
|
|
@@ -8925,7 +9039,7 @@ var headingOf = /* @__PURE__ */ __name((text2) => {
|
|
|
8925
9039
|
}
|
|
8926
9040
|
return void 0;
|
|
8927
9041
|
}, "headingOf");
|
|
8928
|
-
var titleOfName = /* @__PURE__ */ __name((name) => (
|
|
9042
|
+
var titleOfName = /* @__PURE__ */ __name((name) => (basename2(name).replace(/\.[^.]+$/, "") || basename2(name)).slice(0, 200), "titleOfName");
|
|
8929
9043
|
var sha256Of = /* @__PURE__ */ __name((bytes) => createHash2("sha256").update(bytes).digest("hex"), "sha256Of");
|
|
8930
9044
|
var bytesOf = /* @__PURE__ */ __name((value) => Buffer.byteLength(JSON.stringify(value)), "bytesOf");
|
|
8931
9045
|
var documentFields = /* @__PURE__ */ __name((file, { title, text: text2, metadata }) => {
|
|
@@ -8988,7 +9102,7 @@ var hearLocally = /* @__PURE__ */ __name(async (bytes, env) => {
|
|
|
8988
9102
|
const model = speechModel(MODEL);
|
|
8989
9103
|
const directory2 = modelsDirectory(env);
|
|
8990
9104
|
if (!isInstalled(model, directory2))
|
|
8991
|
-
throw new
|
|
9105
|
+
throw new CliError6("not_found", `the speech model ${MODEL} is not on this computer; a WireCat CLI that transcribes downloads it once, such as \`tg models download ${MODEL}\` (${megabytes(installedBytes(model))})`, { reason: "model.not-downloaded", model: MODEL });
|
|
8992
9106
|
const pcm = await decodeAudio(bytes, runFfmpeg);
|
|
8993
9107
|
const pieces = await recognizeLocalPieces(MODEL, pcm, { env, directory: directory2 });
|
|
8994
9108
|
return { pieces, model: MODEL, seconds: pcm.samples.length / pcm.rate };
|
|
@@ -9062,9 +9176,9 @@ var hearAll = /* @__PURE__ */ __name(async (store, files, { provider, account, t
|
|
|
9062
9176
|
import { isCliError as isCliError3 } from "@wirecat/cli-base";
|
|
9063
9177
|
|
|
9064
9178
|
// dist/sources/read.js
|
|
9065
|
-
import { statSync } from "node:fs";
|
|
9066
|
-
import { basename as
|
|
9067
|
-
import { CliError as
|
|
9179
|
+
import { statSync as statSync2 } from "node:fs";
|
|
9180
|
+
import { basename as basename3, extname as extname2 } from "node:path";
|
|
9181
|
+
import { CliError as CliError7, isCliError as isCliError2 } from "@wirecat/cli-base";
|
|
9068
9182
|
import { attachmentMaxBytes as attachmentMaxBytes2, extractText, fetchPage, importEngine, ocrImage, readWhole as readWhole2, sizeText as sizeText2 } from "@wirecat/cli-core/documents";
|
|
9069
9183
|
|
|
9070
9184
|
// dist/sources/transcript.js
|
|
@@ -9135,6 +9249,7 @@ var MIMES = {
|
|
|
9135
9249
|
".xls": "application/vnd.ms-excel",
|
|
9136
9250
|
".odt": "application/vnd.oasis.opendocument.text",
|
|
9137
9251
|
".ods": "application/vnd.oasis.opendocument.spreadsheet",
|
|
9252
|
+
".odp": "application/vnd.oasis.opendocument.presentation",
|
|
9138
9253
|
".epub": "application/epub+zip",
|
|
9139
9254
|
".rtf": "application/rtf",
|
|
9140
9255
|
".vtt": "text/vtt",
|
|
@@ -9163,28 +9278,28 @@ var withNextStep = /* @__PURE__ */ __name((error) => {
|
|
|
9163
9278
|
return error;
|
|
9164
9279
|
const reason = error.details.reason;
|
|
9165
9280
|
const step = typeof reason === "string" ? NEXT[reason] : void 0;
|
|
9166
|
-
return step === void 0 ? error : new
|
|
9281
|
+
return step === void 0 ? error : new CliError7(error.code, `${error.message} \u2014 ${step}`, error.details);
|
|
9167
9282
|
}, "withNextStep");
|
|
9168
9283
|
var refusal = /* @__PURE__ */ __name((extraction, name) => {
|
|
9169
9284
|
switch (extraction.status) {
|
|
9170
9285
|
case "unsupported":
|
|
9171
|
-
return new
|
|
9286
|
+
return new CliError7("validation_error", `no reader takes ${name}`, { reason: "source.unsupported" });
|
|
9172
9287
|
case "unreadable":
|
|
9173
|
-
return new
|
|
9288
|
+
return new CliError7("validation_error", `the ${extraction.extractor} reader could not read ${name}`, {
|
|
9174
9289
|
reason: "source.unreadable"
|
|
9175
9290
|
});
|
|
9176
9291
|
case "engine-missing":
|
|
9177
|
-
return new
|
|
9292
|
+
return new CliError7("configuration_error", `reading ${name} needs ${extraction.engine}, which is not installed`, {
|
|
9178
9293
|
reason: "source.engine-missing"
|
|
9179
9294
|
});
|
|
9180
9295
|
case "too-large":
|
|
9181
|
-
return new
|
|
9296
|
+
return new CliError7("validation_error", `${name} is larger than its reader reads`, { reason: "source.too-large" });
|
|
9182
9297
|
}
|
|
9183
9298
|
}, "refusal");
|
|
9184
|
-
var tooLarge = /* @__PURE__ */ __name((what) => new
|
|
9299
|
+
var tooLarge = /* @__PURE__ */ __name((what) => new CliError7("validation_error", `${what} is larger than ${sizeText2(attachmentMaxBytes2())}; configure MESSAGING_ATTACHMENT_MAX_MIB`, {
|
|
9185
9300
|
reason: "source.too-large"
|
|
9186
9301
|
}), "tooLarge");
|
|
9187
|
-
var noText = /* @__PURE__ */ __name((what) => new
|
|
9302
|
+
var noText = /* @__PURE__ */ __name((what) => new CliError7("validation_error", `${what} holds no text to keep`, { reason: "source.no-text" }), "noText");
|
|
9188
9303
|
var bounded = /* @__PURE__ */ __name((text2, maxChars) => {
|
|
9189
9304
|
const normalized = text2.replace(/\r\n?/g, "\n");
|
|
9190
9305
|
return { text: normalized.slice(0, maxChars), cut: normalized.length > maxChars };
|
|
@@ -9231,12 +9346,12 @@ var readText = /* @__PURE__ */ __name(async (stdin, { maxChars }) => {
|
|
|
9231
9346
|
};
|
|
9232
9347
|
}, "readText");
|
|
9233
9348
|
var readFile = /* @__PURE__ */ __name(async (path, { maxChars, load = importEngine, image }) => {
|
|
9234
|
-
const stat =
|
|
9235
|
-
const name =
|
|
9349
|
+
const stat = statSync2(path, { throwIfNoEntry: false });
|
|
9350
|
+
const name = basename3(path);
|
|
9236
9351
|
if (!stat)
|
|
9237
|
-
throw new
|
|
9352
|
+
throw new CliError7("not_found", `no file ${path}`, { path });
|
|
9238
9353
|
if (!stat.isFile())
|
|
9239
|
-
throw new
|
|
9354
|
+
throw new CliError7("validation_error", `${path} is not a file`, { path });
|
|
9240
9355
|
if (stat.size > attachmentMaxBytes2())
|
|
9241
9356
|
throw tooLarge(name);
|
|
9242
9357
|
const read = await readWhole2(path);
|
|
@@ -9362,7 +9477,10 @@ var previewOf = /* @__PURE__ */ __name((read) => {
|
|
|
9362
9477
|
|
|
9363
9478
|
// dist/import/readers.js
|
|
9364
9479
|
var RECORDS_FILES = /* @__PURE__ */ new Set([".json", ".jsonl"]);
|
|
9365
|
-
var DOCUMENT_EXTENSIONS =
|
|
9480
|
+
var DOCUMENT_EXTENSIONS = Object.fromEntries(NOTE_EXTENSIONS.filter((extension) => !TEXT_EXTENSIONS[extension] && extension !== ".xls").map((extension) => [
|
|
9481
|
+
extension,
|
|
9482
|
+
extension.slice(1)
|
|
9483
|
+
]));
|
|
9366
9484
|
var TRANSCRIPT_EXTENSIONS = { ".vtt": "vtt", ".srt": "srt" };
|
|
9367
9485
|
var readDocument = /* @__PURE__ */ __name(async (file) => {
|
|
9368
9486
|
try {
|
|
@@ -9442,22 +9560,22 @@ var importAccounts = /* @__PURE__ */ __name(async (store) => {
|
|
|
9442
9560
|
}, "importAccounts");
|
|
9443
9561
|
var noAccount = /* @__PURE__ */ __name(async (env) => {
|
|
9444
9562
|
const choices2 = await withStore(env, importAccounts);
|
|
9445
|
-
throw new
|
|
9563
|
+
throw new CliError8("validation_error", `name the account to import into: --account <provider>:<account>. ${choices2.length ? `Accounts that hold imports: ${choices2.join(", ")}.` : "No account holds imports yet."} A new one is made on first use: import:<name> for documents and notes, phone:<exchange> for call transcripts`, { param: "--account", choices: choices2 });
|
|
9446
9564
|
}, "noAccount");
|
|
9447
9565
|
var folderImport = /* @__PURE__ */ __name(async (store, { path, provider, account, dryRun, by, onIssue, transcribe, hear, env }) => {
|
|
9448
9566
|
if (providerNamed(provider)?.imported !== true)
|
|
9449
|
-
throw new
|
|
9567
|
+
throw new CliError8("validation_error", `files are imported only into an account of an import-only provider, which no sync owns: ${provider} is not one. Use import:<name> for documents and notes, or phone:<exchange> for call transcripts`, { param: "--account", reason: "record.provider-not-imported" });
|
|
9450
9568
|
let found;
|
|
9451
9569
|
try {
|
|
9452
9570
|
found = await walk(path);
|
|
9453
9571
|
} catch (error) {
|
|
9454
9572
|
if (error instanceof TooMany)
|
|
9455
|
-
throw new
|
|
9573
|
+
throw new CliError8("validation_error", `${path} holds more than ${MOST_FILES} files: import them by folder`, {
|
|
9456
9574
|
reason: "import.too-many-files",
|
|
9457
9575
|
path
|
|
9458
9576
|
});
|
|
9459
9577
|
if (errnoOf2(error) === "ENOENT")
|
|
9460
|
-
throw new
|
|
9578
|
+
throw new CliError8("not_found", `no file or folder ${path}`, { path });
|
|
9461
9579
|
throw error;
|
|
9462
9580
|
}
|
|
9463
9581
|
const heard = await hearAll(store, found.files, {
|
|
@@ -9515,7 +9633,7 @@ var importCommand = /* @__PURE__ */ __name((program, streams, env, { hear = hear
|
|
|
9515
9633
|
const { print } = answers(program, streams, env);
|
|
9516
9634
|
byOption(annotate(program.command("import"), { effects: LOCAL_WRITE, output: { entity: "import_receipt" } }).summary("bring a folder of documents or a records file into files' search").description("bring a folder of text, Markdown, PDF and Word files, .vtt or .srt transcripts and, with --transcribe, recordings, one such file, or a records file (JSON or JSONL) into the store, under the account you name. Each file is a document keyed by its path in the folder: the same folder twice changes nothing, an edited file updates its document, and a file gone from the folder is kept. Links are not followed and nothing leaves this computer; the text is kept as data, never run")).argument("<path>", "a folder, a .txt, .md, .pdf, .docx, .vtt, .srt or audio file, or a records file (.json, .jsonl; - for stdin)").option("--account <account>", "the source the files belong to: import:<name> (import:handbook), or phone:<exchange> for call transcripts; never chosen for you").option("--transcribe", "hear recordings (.wav, .mp3, .m4a, .ogg, .opus, .flac) with the local speech model; a recording heard before and unchanged is not heard again. Without it recordings are skipped").option("--dry-run", "read every file and plan the import; write nothing. Holds the store's write lock meanwhile").action(async (path, given, command) => {
|
|
9517
9635
|
if (isMcpRun(command, env))
|
|
9518
|
-
throw new
|
|
9636
|
+
throw new CliError8("permission_error", "an agent over MCP hands records over with records import, not a path");
|
|
9519
9637
|
if (!given.account?.trim())
|
|
9520
9638
|
await noAccount(env);
|
|
9521
9639
|
const { provider, account } = sourceOf(given.account);
|
|
@@ -9558,8 +9676,8 @@ var importCommand = /* @__PURE__ */ __name((program, streams, env, { hear = hear
|
|
|
9558
9676
|
}, "importCommand");
|
|
9559
9677
|
|
|
9560
9678
|
// dist/migrate.js
|
|
9561
|
-
import { copyFileSync, existsSync, mkdirSync, readdirSync as readdirSync2, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
9562
|
-
import { join as
|
|
9679
|
+
import { copyFileSync, existsSync as existsSync2, mkdirSync, readdirSync as readdirSync2, readFileSync, realpathSync as realpathSync2, writeFileSync } from "node:fs";
|
|
9680
|
+
import { join as join4 } from "node:path";
|
|
9563
9681
|
import { Credentials, configFilePath as configFilePath2, pathsAreOverridden, resolvePaths as resolvePaths3, saveConfigFile as saveConfigFile2 } from "@wirecat/cli-base";
|
|
9564
9682
|
import { installerOf } from "@wirecat/cli-base/update";
|
|
9565
9683
|
|
|
@@ -9585,7 +9703,7 @@ var readJson = /* @__PURE__ */ __name((path) => {
|
|
|
9585
9703
|
}
|
|
9586
9704
|
}, "readJson");
|
|
9587
9705
|
var isRecord = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !Array.isArray(value), "isRecord");
|
|
9588
|
-
var homeOf = /* @__PURE__ */ __name((env) => MEMO_HOMES.map((home) => resolvePaths3({ ...home, env })).find(({ config, state }) =>
|
|
9706
|
+
var homeOf = /* @__PURE__ */ __name((env) => MEMO_HOMES.map((home) => resolvePaths3({ ...home, env })).find(({ config, state }) => existsSync2(configFilePath2(config)) || existsSync2(join4(state, "folders"))), "homeOf");
|
|
9589
9707
|
var renamedMarks = /* @__PURE__ */ __name((state) => {
|
|
9590
9708
|
if (!isRecord(state) || !isRecord(state.files))
|
|
9591
9709
|
return state;
|
|
@@ -9612,19 +9730,19 @@ var copyConfig = /* @__PURE__ */ __name((from, env) => {
|
|
|
9612
9730
|
return copied.map((key) => `defaults.${key}`);
|
|
9613
9731
|
}, "copyConfig");
|
|
9614
9732
|
var copyFolderStates = /* @__PURE__ */ __name((from, to) => {
|
|
9615
|
-
const source =
|
|
9616
|
-
if (!
|
|
9733
|
+
const source = join4(from, "folders");
|
|
9734
|
+
if (!existsSync2(source))
|
|
9617
9735
|
return 0;
|
|
9618
|
-
const target =
|
|
9736
|
+
const target = join4(to, "folders");
|
|
9619
9737
|
mkdirSync(target, { recursive: true });
|
|
9620
9738
|
let copied = 0;
|
|
9621
9739
|
for (const name of readdirSync2(source)) {
|
|
9622
|
-
if (!name.endsWith(".json") ||
|
|
9740
|
+
if (!name.endsWith(".json") || existsSync2(join4(target, name)))
|
|
9623
9741
|
continue;
|
|
9624
|
-
const state = readJson(
|
|
9742
|
+
const state = readJson(join4(source, name));
|
|
9625
9743
|
if (state === void 0)
|
|
9626
9744
|
continue;
|
|
9627
|
-
writeFileSync(
|
|
9745
|
+
writeFileSync(join4(target, name), JSON.stringify(renamedMarks(state)));
|
|
9628
9746
|
copied++;
|
|
9629
9747
|
}
|
|
9630
9748
|
return copied;
|
|
@@ -9635,10 +9753,10 @@ var copyMaps = /* @__PURE__ */ __name((from, to) => {
|
|
|
9635
9753
|
[from.config, "people-notes.json", to.config],
|
|
9636
9754
|
[from.state, "people-notes-imported.json", to.state]
|
|
9637
9755
|
]) {
|
|
9638
|
-
if (!
|
|
9756
|
+
if (!existsSync2(join4(dir, name)) || existsSync2(join4(into, name)))
|
|
9639
9757
|
continue;
|
|
9640
9758
|
mkdirSync(into, { recursive: true });
|
|
9641
|
-
copyFileSync(
|
|
9759
|
+
copyFileSync(join4(dir, name), join4(into, name));
|
|
9642
9760
|
copied.push(name);
|
|
9643
9761
|
}
|
|
9644
9762
|
return copied;
|
|
@@ -9682,13 +9800,13 @@ var keysIfAnswered = /* @__PURE__ */ __name((env, keyring) => {
|
|
|
9682
9800
|
}
|
|
9683
9801
|
}, "keysIfAnswered");
|
|
9684
9802
|
var writeMarker = /* @__PURE__ */ __name((path, done, keysPending) => {
|
|
9685
|
-
mkdirSync(
|
|
9803
|
+
mkdirSync(join4(path, ".."), { recursive: true });
|
|
9686
9804
|
writeFileSync(path, JSON.stringify({ ...done, keys_pending: keysPending, at: (/* @__PURE__ */ new Date()).toISOString() }));
|
|
9687
9805
|
}, "writeMarker");
|
|
9688
9806
|
var migrateFromMemo = /* @__PURE__ */ __name((env, keyring) => {
|
|
9689
9807
|
const own = filesPaths(env);
|
|
9690
|
-
const marker =
|
|
9691
|
-
if (
|
|
9808
|
+
const marker = join4(own.state, MARKER);
|
|
9809
|
+
if (existsSync2(marker)) {
|
|
9692
9810
|
const saved = readJson(marker);
|
|
9693
9811
|
if (!isRecord(saved) || saved.keys_pending !== true)
|
|
9694
9812
|
return void 0;
|
|
@@ -9715,7 +9833,7 @@ var isInstalledCopy = /* @__PURE__ */ __name((script) => {
|
|
|
9715
9833
|
if (!script)
|
|
9716
9834
|
return false;
|
|
9717
9835
|
try {
|
|
9718
|
-
const installer = installerOf(
|
|
9836
|
+
const installer = installerOf(realpathSync2(script));
|
|
9719
9837
|
return installer !== "checkout" && installer !== "unknown";
|
|
9720
9838
|
} catch {
|
|
9721
9839
|
return false;
|
|
@@ -9726,6 +9844,7 @@ var isInstalledCopy = /* @__PURE__ */ __name((script) => {
|
|
|
9726
9844
|
import { readFileSync as readFileSync5 } from "node:fs";
|
|
9727
9845
|
import { CliError as CliError17 } from "@wirecat/cli-base";
|
|
9728
9846
|
import { annotate as annotate2 } from "@wirecat/cli-base/commands";
|
|
9847
|
+
import { stepOf } from "@wirecat/cli-base/standards";
|
|
9729
9848
|
import { contextEvidenceFingerprint, LOCAL_READ, LOCAL_WRITE as LOCAL_WRITE2, queryTerms, termField, withQuery } from "@wirecat/cli-core";
|
|
9730
9849
|
import { InvalidArgumentError as InvalidArgumentError2 } from "commander";
|
|
9731
9850
|
|
|
@@ -9738,83 +9857,21 @@ var positive = /* @__PURE__ */ __name((value) => {
|
|
|
9738
9857
|
return number;
|
|
9739
9858
|
}, "positive");
|
|
9740
9859
|
var collect = /* @__PURE__ */ __name((value, previous = []) => [...previous, value], "collect");
|
|
9860
|
+
var between = /* @__PURE__ */ __name((low, high, what) => (value) => {
|
|
9861
|
+
const number = Number(value);
|
|
9862
|
+
if (!Number.isInteger(number) || number < low || number > high)
|
|
9863
|
+
throw new InvalidArgumentError(`${what}: a whole number, ${low} to ${high}`);
|
|
9864
|
+
return number;
|
|
9865
|
+
}, "between");
|
|
9741
9866
|
|
|
9742
9867
|
// dist/people/notes-map.js
|
|
9743
|
-
import { existsSync as
|
|
9868
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
9744
9869
|
import { join as join6 } from "node:path";
|
|
9745
9870
|
import { loadConfigFile } from "@wirecat/cli-base";
|
|
9746
9871
|
|
|
9747
9872
|
// dist/notes/bound.js
|
|
9748
|
-
import { resolve as resolve2 } from "node:path";
|
|
9873
|
+
import { isAbsolute, relative as relative3, resolve as resolve2, sep as sep4 } from "node:path";
|
|
9749
9874
|
import { CliError as CliError9 } from "@wirecat/cli-base";
|
|
9750
|
-
|
|
9751
|
-
// dist/notes/folders.js
|
|
9752
|
-
import { realpathSync as realpathSync2, statSync as statSync2 } from "node:fs";
|
|
9753
|
-
import { dirname, join as join4, resolve, sep as sep3 } from "node:path";
|
|
9754
|
-
import { CliError as CliError8 } from "@wirecat/cli-base";
|
|
9755
|
-
var entryOf = /* @__PURE__ */ __name((entry) => typeof entry === "string" ? { id: null, path: resolve(entry), format: "obsidian" } : { id: entry.id, path: resolve(entry.path), format: entry.format ?? "obsidian" }, "entryOf");
|
|
9756
|
-
var noteFolders = /* @__PURE__ */ __name((notes) => (notes?.folders ?? []).map(entryOf), "noteFolders");
|
|
9757
|
-
var written = /* @__PURE__ */ __name((folder) => ({
|
|
9758
|
-
id: folder.id,
|
|
9759
|
-
path: folder.path,
|
|
9760
|
-
...folder.format === "obsidian" ? {} : { format: folder.format }
|
|
9761
|
-
}), "written");
|
|
9762
|
-
var withFolders = /* @__PURE__ */ __name((config, folders) => ({
|
|
9763
|
-
...config,
|
|
9764
|
-
notes: {
|
|
9765
|
-
...config.notes,
|
|
9766
|
-
folders: folders.map((folder) => folder.id === null ? folder.path : written(folder))
|
|
9767
|
-
}
|
|
9768
|
-
}), "withFolders");
|
|
9769
|
-
var bindFolder = /* @__PURE__ */ __name((config, folder) => {
|
|
9770
|
-
const at = resolve(folder.path);
|
|
9771
|
-
const folders = noteFolders(config.notes);
|
|
9772
|
-
const index = folders.findIndex((other) => other.path === at);
|
|
9773
|
-
const bound = { ...folder, path: at };
|
|
9774
|
-
const kept = folders.map((other, position) => position === index ? bound : other).filter((other, position) => position === index || other.id !== folder.id && other.path !== at);
|
|
9775
|
-
return withFolders(config, index < 0 ? [...kept, bound] : kept);
|
|
9776
|
-
}, "bindFolder");
|
|
9777
|
-
var attachFolder = /* @__PURE__ */ __name((config, id, path, format) => {
|
|
9778
|
-
const at = resolve(path);
|
|
9779
|
-
const folders = noteFolders(config.notes);
|
|
9780
|
-
const taken = folders.find((folder2) => folder2.path === at && folder2.id !== null && folder2.id !== id);
|
|
9781
|
-
if (taken)
|
|
9782
|
-
throw new CliError8("validation_error", `${at} is already folder ${taken.id} \u2014 attach that id elsewhere first, or remove it from the config`);
|
|
9783
|
-
const previous = folders.find((folder2) => folder2.id === id);
|
|
9784
|
-
const folder = { id, path: at, format: format ?? previous?.format ?? "obsidian" };
|
|
9785
|
-
const kept = folders.filter((other) => other.id !== id && other.path !== at);
|
|
9786
|
-
return { config: withFolders(config, [...kept, folder]), folder };
|
|
9787
|
-
}, "attachFolder");
|
|
9788
|
-
var unbindFolder = /* @__PURE__ */ __name((config, path) => withFolders(config, noteFolders(config.notes).filter((folder) => folder.path !== resolve(path))), "unbindFolder");
|
|
9789
|
-
var real = /* @__PURE__ */ __name((path) => {
|
|
9790
|
-
try {
|
|
9791
|
-
return realpathSync2(path);
|
|
9792
|
-
} catch {
|
|
9793
|
-
return resolve(path);
|
|
9794
|
-
}
|
|
9795
|
-
}, "real");
|
|
9796
|
-
var detectFormat = /* @__PURE__ */ __name((path) => {
|
|
9797
|
-
for (let at = real(path); ; at = dirname(at)) {
|
|
9798
|
-
try {
|
|
9799
|
-
if (statSync2(join4(at, ".obsidian")).isDirectory())
|
|
9800
|
-
return "obsidian";
|
|
9801
|
-
} catch {
|
|
9802
|
-
}
|
|
9803
|
-
if (dirname(at) === at)
|
|
9804
|
-
return "markdown";
|
|
9805
|
-
}
|
|
9806
|
-
}, "detectFormat");
|
|
9807
|
-
var comparable = /* @__PURE__ */ __name((path) => process.platform === "darwin" || process.platform === "win32" ? real(path).toLowerCase() : real(path), "comparable");
|
|
9808
|
-
var inside = /* @__PURE__ */ __name((child, parent) => child.startsWith(parent.endsWith(sep3) ? parent : `${parent}${sep3}`), "inside");
|
|
9809
|
-
var overlapping = /* @__PURE__ */ __name((folders, path) => {
|
|
9810
|
-
const at = comparable(path);
|
|
9811
|
-
return folders.filter((folder) => {
|
|
9812
|
-
const other = comparable(folder.path);
|
|
9813
|
-
return other !== at && (inside(at, other) || inside(other, at));
|
|
9814
|
-
});
|
|
9815
|
-
}, "overlapping");
|
|
9816
|
-
|
|
9817
|
-
// dist/notes/bound.js
|
|
9818
9875
|
var UNBOUND = "folder.unbound";
|
|
9819
9876
|
var unboundReason = /* @__PURE__ */ __name((path) => `${path} has no folder id \u2014 files folders add ${path}, or files folders update <id> ${path} if another computer made one`, "unboundReason");
|
|
9820
9877
|
var unbound = /* @__PURE__ */ __name((path) => new CliError9("configuration_error", unboundReason(path), { reason: UNBOUND, path }), "unbound");
|
|
@@ -9837,19 +9894,21 @@ var boundFolders = /* @__PURE__ */ __name(async (store, env, { only, strict = tr
|
|
|
9837
9894
|
}, "boundFolders");
|
|
9838
9895
|
var folderOfFile = /* @__PURE__ */ __name((folders, file) => {
|
|
9839
9896
|
const at = resolve2(file);
|
|
9840
|
-
const folder
|
|
9841
|
-
|
|
9842
|
-
|
|
9843
|
-
|
|
9897
|
+
for (const folder of folders) {
|
|
9898
|
+
const path = relative3(folder.path, at);
|
|
9899
|
+
if (path && path !== ".." && !path.startsWith(`..${sep4}`) && !isAbsolute(path))
|
|
9900
|
+
return { folder, path: path.split(sep4).join("/") };
|
|
9901
|
+
}
|
|
9902
|
+
throw new CliError9("not_found", `${at} is in no configured folder of notes`, { reason: "folder.not-found" });
|
|
9844
9903
|
}, "folderOfFile");
|
|
9845
9904
|
|
|
9846
9905
|
// dist/notes/import.js
|
|
9847
9906
|
import { createHash as createHash3 } from "node:crypto";
|
|
9848
|
-
import { existsSync as
|
|
9849
|
-
import { basename as
|
|
9850
|
-
import { CliError as CliError10 } from "@wirecat/cli-base";
|
|
9907
|
+
import { existsSync as existsSync3, statSync as statSync3 } from "node:fs";
|
|
9908
|
+
import { basename as basename4, extname as extname3, relative as relative4, sep as sep5 } from "node:path";
|
|
9909
|
+
import { CliError as CliError10, isCliError as isCliError4 } from "@wirecat/cli-base";
|
|
9851
9910
|
import { normalizeTag } from "@wirecat/cli-core";
|
|
9852
|
-
import { attachmentMaxBytes as attachmentMaxBytes3, extractText as extractText2, importEngine as importEngine2, readWhole as readWhole3 } from "@wirecat/cli-core/documents";
|
|
9911
|
+
import { attachmentMaxBytes as attachmentMaxBytes3, extractText as extractText2, importEngine as importEngine2, readWhole as readWhole3, scanRetry } from "@wirecat/cli-core/documents";
|
|
9853
9912
|
|
|
9854
9913
|
// dist/notes/dates.js
|
|
9855
9914
|
var BARE_DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
@@ -9868,7 +9927,8 @@ var noteFileTime = /* @__PURE__ */ __name((frontMatter, mtimeMs) => new Date(fro
|
|
|
9868
9927
|
// dist/notes/links.js
|
|
9869
9928
|
import { posix as posix2 } from "node:path";
|
|
9870
9929
|
var fold = /* @__PURE__ */ __name((value) => value.normalize("NFC").toLocaleLowerCase("en"), "fold");
|
|
9871
|
-
var
|
|
9930
|
+
var STEM = new RegExp(`\\.(${[...NOTE_EXTENSIONS, ...PICTURE_EXTENSIONS].map((ext) => ext.slice(1)).join("|")})$`, "i");
|
|
9931
|
+
var stem = /* @__PURE__ */ __name((path) => path.replace(STEM, ""), "stem");
|
|
9872
9932
|
var aliasesOf = /* @__PURE__ */ __name((frontMatter) => {
|
|
9873
9933
|
const value = frontMatter?.aliases ?? frontMatter?.alias;
|
|
9874
9934
|
if (typeof value === "string")
|
|
@@ -9882,9 +9942,9 @@ var documentOf = /* @__PURE__ */ __name((note) => ({
|
|
|
9882
9942
|
}), "documentOf");
|
|
9883
9943
|
var notesNamed = /* @__PURE__ */ __name((source, target, documents) => {
|
|
9884
9944
|
const normalized = stem(posix2.normalize(target.replace(/\\/g, "/").replace(/^\//, "")));
|
|
9885
|
-
const
|
|
9945
|
+
const relative6 = stem(posix2.normalize(posix2.join(posix2.dirname(source), normalized)));
|
|
9886
9946
|
const explicit = target.startsWith("./") || target.startsWith("../") || target.startsWith("/") || normalized.includes("/");
|
|
9887
|
-
const preferred = target.startsWith("./") || target.startsWith("../") ?
|
|
9947
|
+
const preferred = target.startsWith("./") || target.startsWith("../") ? relative6 : normalized;
|
|
9888
9948
|
if (target === "")
|
|
9889
9949
|
return documents.filter((doc) => doc.path === source);
|
|
9890
9950
|
if (explicit)
|
|
@@ -9952,7 +10012,7 @@ var PAGE = 500;
|
|
|
9952
10012
|
var TEXT_NOTE2 = /\.(md|markdown|txt)$/i;
|
|
9953
10013
|
var MEMO = "files:";
|
|
9954
10014
|
var missingFolder = /* @__PURE__ */ __name((path) => `the notes folder ${path} is missing \u2014 connect its disk; if it moved, files folders update <id> <new path>`, "missingFolder");
|
|
9955
|
-
var inside2 = /* @__PURE__ */ __name((folder, path) =>
|
|
10015
|
+
var inside2 = /* @__PURE__ */ __name((folder, path) => relative4(folder, path).split(sep5).join("/"), "inside");
|
|
9956
10016
|
var folderNotes = /* @__PURE__ */ __name(async (store, folderId) => {
|
|
9957
10017
|
const notes = [];
|
|
9958
10018
|
for (let offset = 0; ; offset += PAGE) {
|
|
@@ -9971,9 +10031,9 @@ var storable = /* @__PURE__ */ __name((tags) => [
|
|
|
9971
10031
|
}
|
|
9972
10032
|
}))
|
|
9973
10033
|
].sort(), "storable");
|
|
9974
|
-
var importNotes = /* @__PURE__ */ __name(async (store, folder, { ignore = [], skip = [], env = process.env, loadEngine = importEngine2, onFile = /* @__PURE__ */ __name(() => {
|
|
10034
|
+
var importNotes = /* @__PURE__ */ __name(async (store, folder, { ignore = [], skip = [], env = process.env, loadEngine = importEngine2, scans, onFile = /* @__PURE__ */ __name(() => {
|
|
9975
10035
|
}, "onFile") } = {}) => {
|
|
9976
|
-
if (!
|
|
10036
|
+
if (!existsSync3(folder.path))
|
|
9977
10037
|
throw new CliError10("not_found", missingFolder(folder.path), {
|
|
9978
10038
|
reason: "notes.folder-missing",
|
|
9979
10039
|
path: folder.path
|
|
@@ -9991,13 +10051,18 @@ var importNotes = /* @__PURE__ */ __name(async (store, folder, { ignore = [], sk
|
|
|
9991
10051
|
const unreadable2 = [];
|
|
9992
10052
|
const read = [];
|
|
9993
10053
|
const mtimes = /* @__PURE__ */ new Map();
|
|
9994
|
-
const notReadAs = /* @__PURE__ */ __name((path, status, engine) => {
|
|
9995
|
-
const entry = { status, ...engine === void 0 ? {} : { engine } };
|
|
10054
|
+
const notReadAs = /* @__PURE__ */ __name((path, status, engine, reason) => {
|
|
10055
|
+
const entry = { status, ...engine === void 0 ? {} : { engine }, ...reason === void 0 ? {} : { reason } };
|
|
9996
10056
|
notRead.push({ path, ...entry });
|
|
9997
10057
|
notReadNow[path] = entry;
|
|
9998
10058
|
unreadable2.push(path);
|
|
9999
10059
|
}, "notReadAs");
|
|
10000
|
-
const
|
|
10060
|
+
const reads = scans?.extractor !== void 0;
|
|
10061
|
+
const refused = reads ? await refusal2(scans, { name: "probe.pdf", mime: "application/pdf" }) : void 0;
|
|
10062
|
+
const ocr = { read: 0, picturesWaiting: 0 };
|
|
10063
|
+
const scanned = /* @__PURE__ */ __name((id) => isPicturePath(id) || extname3(id).toLowerCase() === ".pdf", "scanned");
|
|
10064
|
+
const retried = /* @__PURE__ */ __name((id, entry) => reads && entry?.status === "needs-agent" && scanned(id) && (entry.reason === void 0 || entry.reason !== refused && scanRetry(scans, entry.reason)), "retried");
|
|
10065
|
+
const files = noteFiles(folder.path, ignore, [...NOTE_EXTENSIONS, ...PICTURE_EXTENSIONS], { skipExported: false });
|
|
10001
10066
|
onFile(0, files.length);
|
|
10002
10067
|
for (const [index, path] of files.entries()) {
|
|
10003
10068
|
if (index > 0)
|
|
@@ -10005,7 +10070,13 @@ var importNotes = /* @__PURE__ */ __name(async (store, folder, { ignore = [], sk
|
|
|
10005
10070
|
const id = inside2(folder.path, path);
|
|
10006
10071
|
const previous = before?.files[id];
|
|
10007
10072
|
const wasNotRead = before?.notRead?.[id];
|
|
10008
|
-
|
|
10073
|
+
const waiting = !reads && isPicturePath(id);
|
|
10074
|
+
if (waiting && !stored.has(id)) {
|
|
10075
|
+
if (scans)
|
|
10076
|
+
ocr.picturesWaiting++;
|
|
10077
|
+
continue;
|
|
10078
|
+
}
|
|
10079
|
+
if (skipped(id) || waiting) {
|
|
10009
10080
|
held.add(id);
|
|
10010
10081
|
if (previous !== void 0)
|
|
10011
10082
|
after.files[id] = previous;
|
|
@@ -10017,11 +10088,11 @@ var importNotes = /* @__PURE__ */ __name(async (store, folder, { ignore = [], sk
|
|
|
10017
10088
|
mtimes.set(id, stat.mtimeMs);
|
|
10018
10089
|
const stamp = `${stat.mtimeMs}:${stat.size}:`;
|
|
10019
10090
|
const exported = previous?.startsWith(`${MEMO}${stamp}`);
|
|
10020
|
-
const settled = stored.has(id) || wasNotRead !== void 0 && wasNotRead.status !== "engine-missing" && wasNotRead.status !== "too-large";
|
|
10091
|
+
const settled = stored.has(id) || wasNotRead !== void 0 && wasNotRead.status !== "engine-missing" && wasNotRead.status !== "too-large" && !retried(id, wasNotRead);
|
|
10021
10092
|
if (exported || previous?.startsWith(stamp) && settled && !reparse(id)) {
|
|
10022
10093
|
after.files[id] = previous;
|
|
10023
10094
|
if (wasNotRead)
|
|
10024
|
-
notReadAs(id, wasNotRead.status, wasNotRead.engine);
|
|
10095
|
+
notReadAs(id, wasNotRead.status, wasNotRead.engine, wasNotRead.reason);
|
|
10025
10096
|
continue;
|
|
10026
10097
|
}
|
|
10027
10098
|
if (stat.size > attachmentMaxBytes3()) {
|
|
@@ -10036,7 +10107,7 @@ var importNotes = /* @__PURE__ */ __name(async (store, folder, { ignore = [], sk
|
|
|
10036
10107
|
const bytes = await readWhole3(path);
|
|
10037
10108
|
const hash = createHash3("sha256").update(bytes).digest("hex");
|
|
10038
10109
|
after.files[id] = `${stamp}${hash}`;
|
|
10039
|
-
read.push({ id, path, bytes, hash });
|
|
10110
|
+
read.push({ id, path, bytes: isPicturePath(id) ? null : bytes, hash });
|
|
10040
10111
|
}
|
|
10041
10112
|
const listed = /* @__PURE__ */ new Set([
|
|
10042
10113
|
...Object.keys(after.files).filter((id) => !after.files[id]?.startsWith(MEMO)),
|
|
@@ -10058,7 +10129,20 @@ var importNotes = /* @__PURE__ */ __name(async (store, folder, { ignore = [], sk
|
|
|
10058
10129
|
onFile(files.length - read.length + index, files.length);
|
|
10059
10130
|
if (stored.get(id)?.contentHash === hash && !reparse(id))
|
|
10060
10131
|
continue;
|
|
10061
|
-
|
|
10132
|
+
let extraction = bytes === null ? { status: "needs-agent" } : await extractText2(bytes, { kind: "file", name: basename4(path), mime: null, path }, loadEngine);
|
|
10133
|
+
if (extraction.status === "needs-agent" && scans && scanned(id)) {
|
|
10134
|
+
const mime = MIMES[extname3(id).toLowerCase()] ?? "application/octet-stream";
|
|
10135
|
+
try {
|
|
10136
|
+
const text3 = await scans.read(async () => bytes ?? await readWhole3(path), { name: basename4(path), mime });
|
|
10137
|
+
extraction = { status: "extracted", text: text3, extractor: scans.extractor ?? "ocr" };
|
|
10138
|
+
ocr.read++;
|
|
10139
|
+
} catch (error) {
|
|
10140
|
+
if (!isCliError4(error) || error.code !== "validation_error")
|
|
10141
|
+
throw error;
|
|
10142
|
+
notReadAs(id, "needs-agent", void 0, error.message);
|
|
10143
|
+
continue;
|
|
10144
|
+
}
|
|
10145
|
+
}
|
|
10062
10146
|
if (extraction.status !== "extracted") {
|
|
10063
10147
|
notReadAs(id, extraction.status, "engine" in extraction ? extraction.engine : void 0);
|
|
10064
10148
|
continue;
|
|
@@ -10070,7 +10154,7 @@ var importNotes = /* @__PURE__ */ __name(async (store, folder, { ignore = [], sk
|
|
|
10070
10154
|
const saved = await store.notes.saveFileNote({
|
|
10071
10155
|
folderId: folder.id,
|
|
10072
10156
|
path: id,
|
|
10073
|
-
title: note?.title ??
|
|
10157
|
+
title: note?.title ?? basename4(id).replace(/\.[^.]+$/, ""),
|
|
10074
10158
|
text: text2.slice(0, MAX_TEXT),
|
|
10075
10159
|
...note && Object.keys(note.frontMatter).length ? { frontMatter: note.frontMatter } : {},
|
|
10076
10160
|
contentHash: hash
|
|
@@ -10134,6 +10218,7 @@ var importNotes = /* @__PURE__ */ __name(async (store, folder, { ignore = [], sk
|
|
|
10134
10218
|
await store.notes.replaceFileTags(stored.get(id).id, storable(note.tags));
|
|
10135
10219
|
const heldBack = [...held].some((id) => reparse(id) && stored.has(id));
|
|
10136
10220
|
saveFolderState(env, folder.id, { ...after, format: heldBack ? before?.format : folder.format });
|
|
10221
|
+
const scansNotRead = notRead.filter(({ reason }) => reason !== void 0).length;
|
|
10137
10222
|
return {
|
|
10138
10223
|
folder: folder.path,
|
|
10139
10224
|
folderId: folder.id,
|
|
@@ -10143,16 +10228,25 @@ var importNotes = /* @__PURE__ */ __name(async (store, folder, { ignore = [], sk
|
|
|
10143
10228
|
deleted,
|
|
10144
10229
|
...notRead.length ? { notRead } : {},
|
|
10145
10230
|
...truncated.length ? { truncated } : {},
|
|
10146
|
-
...deletionsSkipped === void 0 ? {} : { deletionsSkipped }
|
|
10231
|
+
...deletionsSkipped === void 0 ? {} : { deletionsSkipped },
|
|
10232
|
+
...ocr.read + scansNotRead + ocr.picturesWaiting > 0 ? {
|
|
10233
|
+
ocr: {
|
|
10234
|
+
read: ocr.read,
|
|
10235
|
+
notRead: scansNotRead,
|
|
10236
|
+
...ocr.picturesWaiting ? { picturesWaiting: ocr.picturesWaiting } : {},
|
|
10237
|
+
...!reads && scans ? { unavailable: await refusal2(scans, { name: "probe.png", mime: "image/png" }) } : {}
|
|
10238
|
+
}
|
|
10239
|
+
} : {}
|
|
10147
10240
|
};
|
|
10148
10241
|
}, "importNotes");
|
|
10242
|
+
var refusal2 = /* @__PURE__ */ __name((scans, file) => scans.read(async () => new Uint8Array(), file).then(() => "", (error) => error instanceof Error ? error.message : String(error)), "refusal");
|
|
10149
10243
|
|
|
10150
10244
|
// dist/people/notes-map.js
|
|
10151
10245
|
var NotesMapSchema = record(string(), string());
|
|
10152
10246
|
var mapPath = /* @__PURE__ */ __name((env) => join6(filesPaths(env).config, "people-notes.json"), "mapPath");
|
|
10153
10247
|
var donePath = /* @__PURE__ */ __name((env) => join6(filesPaths(env).state, "people-notes-imported.json"), "donePath");
|
|
10154
10248
|
var importNotesMap = /* @__PURE__ */ __name(async (store, env, folders) => {
|
|
10155
|
-
if (!
|
|
10249
|
+
if (!existsSync4(mapPath(env)))
|
|
10156
10250
|
return 0;
|
|
10157
10251
|
const map = loadConfigFile(mapPath(env), NotesMapSchema, () => ({}));
|
|
10158
10252
|
let done = [];
|
|
@@ -10363,7 +10457,7 @@ import { CliError as CliError16 } from "@wirecat/cli-base";
|
|
|
10363
10457
|
|
|
10364
10458
|
// dist/notes/export.js
|
|
10365
10459
|
import { createHash as createHash4 } from "node:crypto";
|
|
10366
|
-
import { existsSync as
|
|
10460
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync4, readdirSync as readdirSync3, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync4 } from "node:fs";
|
|
10367
10461
|
import { join as join7 } from "node:path";
|
|
10368
10462
|
var HASH_LINE = /^memo-hash: .*\r?\n/m;
|
|
10369
10463
|
var PLACEHOLDER = "f".repeat(64);
|
|
@@ -10405,7 +10499,7 @@ var exportNotes = /* @__PURE__ */ __name(({ dir, dialect, notes }) => {
|
|
|
10405
10499
|
frontMatter["memo-hash"] = PLACEHOLDER;
|
|
10406
10500
|
const content = withHash(dialect.render({ ...note, frontMatter }));
|
|
10407
10501
|
const known = existing.get(id);
|
|
10408
|
-
const name = known ?? fileName(note.title, id, (candidate) => claimed.has(candidate) ||
|
|
10502
|
+
const name = known ?? fileName(note.title, id, (candidate) => claimed.has(candidate) || existsSync5(join7(dir, candidate)));
|
|
10409
10503
|
claimed.add(name);
|
|
10410
10504
|
const path = join7(dir, name);
|
|
10411
10505
|
if (known !== void 0) {
|
|
@@ -10536,6 +10630,18 @@ var noteOf = /* @__PURE__ */ __name(async (store, env, reference) => {
|
|
|
10536
10630
|
});
|
|
10537
10631
|
return found;
|
|
10538
10632
|
}, "noteOf");
|
|
10633
|
+
var MAX_CHARS = 2e5;
|
|
10634
|
+
var SHOW_WHOLE = {
|
|
10635
|
+
id: "show.whole",
|
|
10636
|
+
kind: "command",
|
|
10637
|
+
command: "notes show",
|
|
10638
|
+
args: [{ name: "note", required: true }],
|
|
10639
|
+
why: "the whole text of {note}"
|
|
10640
|
+
};
|
|
10641
|
+
var cutText = /* @__PURE__ */ __name((text2, maxChars) => {
|
|
10642
|
+
const whole = Array.from(text2);
|
|
10643
|
+
return maxChars === void 0 || whole.length <= maxChars ? void 0 : { text: whole.slice(0, maxChars).join(""), length: whole.length };
|
|
10644
|
+
}, "cutText");
|
|
10539
10645
|
var notesCommandDefinition = /* @__PURE__ */ __name((program, streams, env) => {
|
|
10540
10646
|
const { print } = answers(program, streams, env);
|
|
10541
10647
|
const exportedPath = /* @__PURE__ */ __name(({ written: written2, unchanged, edited }) => {
|
|
@@ -10549,8 +10655,8 @@ var notesCommandDefinition = /* @__PURE__ */ __name((program, streams, env) => {
|
|
|
10549
10655
|
return work(store);
|
|
10550
10656
|
}), "withNotes");
|
|
10551
10657
|
const notes = program.command("notes").description("notes from your folders, and notes you write here");
|
|
10552
|
-
annotate2(notes.command("show"), { effects: LOCAL_READ, output: { entity: "note" } }).description("one note: its text, tags, what it links and what links it").addHelpText("after", SAVE_HELP).argument("<note>", "note:<id>, document:<id>, or a file in a configured folder").action(async (reference, options) => {
|
|
10553
|
-
const
|
|
10658
|
+
annotate2(notes.command("show"), { effects: LOCAL_READ, output: { entity: "note" } }).description("one note: its text, tags, what it links and what links it").addHelpText("after", SAVE_HELP).argument("<note>", "note:<id>, document:<id>, or a file in a configured folder").option("--max-chars <n>", `characters of the text at most, 1\u2013${MAX_CHARS}; the whole text without it`, between(1, MAX_CHARS, "--max-chars")).action(async (reference, options) => {
|
|
10659
|
+
const whole = await withNotes(async (store) => {
|
|
10554
10660
|
const note = await noteOf(store, env, reference);
|
|
10555
10661
|
const ref = note.ref;
|
|
10556
10662
|
return {
|
|
@@ -10572,11 +10678,19 @@ var notesCommandDefinition = /* @__PURE__ */ __name((program, streams, env) => {
|
|
|
10572
10678
|
fingerprint: await citedFingerprint(store, ref)
|
|
10573
10679
|
};
|
|
10574
10680
|
});
|
|
10575
|
-
|
|
10681
|
+
const cut = cutText(whole.text, options.maxChars);
|
|
10682
|
+
const answer = cut ? { ...whole, text: cut.text } : whole;
|
|
10683
|
+
const shortened = cut && {
|
|
10684
|
+
next: [stepOf(SHOW_WHOLE, { args: { note: answer.ref } })],
|
|
10685
|
+
missing: [{ field: "text", why: `cut at ${options.maxChars} of ${cut.length} characters by --max-chars` }],
|
|
10686
|
+
meta: { complete: false }
|
|
10687
|
+
};
|
|
10688
|
+
print(options.json, itemAnswer(answer, shortened), [
|
|
10576
10689
|
`${answer.ref} ${answer.path ?? answer.title ?? ""}`.trimEnd(),
|
|
10577
10690
|
` updated ${new Date(answer.updatedAt).toISOString().slice(0, 16).replace("T", " ")}${answer.tags.length ? ` tags: ${answer.tags.join(", ")}` : ""}`,
|
|
10578
10691
|
"",
|
|
10579
10692
|
answer.text,
|
|
10693
|
+
...cut ? [` \u2026 ${cut.length} characters in all`] : [],
|
|
10580
10694
|
...answer.links.length ? ["", `links: ${answer.links.map(({ to, targetText }) => to ?? `${targetText} (not found)`).join(", ")}`] : [],
|
|
10581
10695
|
...answer.backlinks.length ? [`linked from: ${answer.backlinks.map(({ from }) => from).join(", ")}`] : []
|
|
10582
10696
|
].join("\n"));
|
|
@@ -10670,7 +10784,7 @@ var notesCommand = notesCommandDefinition;
|
|
|
10670
10784
|
|
|
10671
10785
|
// dist/notes/folders-command.js
|
|
10672
10786
|
import { statSync as statSync4 } from "node:fs";
|
|
10673
|
-
import { basename as
|
|
10787
|
+
import { basename as basename5, resolve as resolve4 } from "node:path";
|
|
10674
10788
|
import { CliError as CliError19 } from "@wirecat/cli-base";
|
|
10675
10789
|
import { annotate as annotate3 } from "@wirecat/cli-base/commands";
|
|
10676
10790
|
import { grantsAuthority, LOCAL_READ as LOCAL_READ2, LOCAL_WRITE as LOCAL_WRITE3, notLocalPaths, queryTerms as queryTerms2, withQuery as withQuery2 } from "@wirecat/cli-core";
|
|
@@ -10740,7 +10854,7 @@ var foldersCommand = /* @__PURE__ */ __name((program, streams, env) => {
|
|
|
10740
10854
|
throw new CliError19("validation_error", `${at} is inside or around ${clash.path}, which files already reads \u2014 one file would be two notes; remove one of them first (files folders remove "${clash.path}")`, { reason: "folder.overlap", path: at, other: clash.path });
|
|
10741
10855
|
const saved = current?.id === null ? void 0 : current?.format;
|
|
10742
10856
|
const format = options.format ?? saved ?? detectFormat(at);
|
|
10743
|
-
const made = await store.notes.addFolder({ name:
|
|
10857
|
+
const made = await store.notes.addFolder({ name: basename5(at) || at, format });
|
|
10744
10858
|
const folder = { id: made.id, path: at, format };
|
|
10745
10859
|
updateConfig((config) => bindFolder(config, folder), env);
|
|
10746
10860
|
const from = options.format ? "option" : saved ? "saved" : "detected";
|
|
@@ -10821,9 +10935,91 @@ var foldersCommand = /* @__PURE__ */ __name((program, streams, env) => {
|
|
|
10821
10935
|
});
|
|
10822
10936
|
}, "foldersCommand");
|
|
10823
10937
|
|
|
10824
|
-
// dist/
|
|
10938
|
+
// dist/people/command.js
|
|
10939
|
+
import { join as join9 } from "node:path";
|
|
10940
|
+
import { CliError as CliError20 } from "@wirecat/cli-base";
|
|
10825
10941
|
import { annotate as annotate4 } from "@wirecat/cli-base/commands";
|
|
10826
|
-
import { LOCAL_READ as LOCAL_READ3,
|
|
10942
|
+
import { LOCAL_READ as LOCAL_READ3, LOCAL_WRITE as LOCAL_WRITE4 } from "@wirecat/cli-core";
|
|
10943
|
+
var noteLinksCommand = /* @__PURE__ */ __name((program, streams, env) => {
|
|
10944
|
+
const notes = program.commands.find((command) => command.name() === "notes") ?? program.command("notes");
|
|
10945
|
+
const links = notes.command("links").description("imported note files linked to the person behind an identity");
|
|
10946
|
+
const { print } = answers(program, streams, env);
|
|
10947
|
+
for (const operation of ["show", "add", "clear"]) {
|
|
10948
|
+
const command = annotate4(links.command(operation), {
|
|
10949
|
+
effects: operation === "show" ? LOCAL_READ3 : LOCAL_WRITE4,
|
|
10950
|
+
output: { entity: "person_note_links" },
|
|
10951
|
+
examples: [
|
|
10952
|
+
{
|
|
10953
|
+
show: "files notes links show telegram:'Kai Sample'",
|
|
10954
|
+
add: "files notes links add telegram:'Kai Sample' /path/to/vault/People/Kai.md",
|
|
10955
|
+
clear: "files notes links clear telegram:'Kai Sample'"
|
|
10956
|
+
}[operation]
|
|
10957
|
+
]
|
|
10958
|
+
}).description({
|
|
10959
|
+
show: "show the note files about a person",
|
|
10960
|
+
add: "link an imported note file to a person",
|
|
10961
|
+
clear: "remove the owner's note-file links for a person"
|
|
10962
|
+
}[operation]).argument("<identity>", "<messenger>:<name or id> of an identity of the person").option("--json", "print the standard JSON answer");
|
|
10963
|
+
if (operation === "add")
|
|
10964
|
+
command.argument("<path>", "the imported note file in a configured folder");
|
|
10965
|
+
if (operation !== "show")
|
|
10966
|
+
byOption(command);
|
|
10967
|
+
command.action(async (identity, ...rest) => {
|
|
10968
|
+
const options = command.opts();
|
|
10969
|
+
const path = operation === "add" ? String(rest[0]) : void 0;
|
|
10970
|
+
let by = "owner";
|
|
10971
|
+
if (operation !== "show") {
|
|
10972
|
+
const who = await whoRuns(command, env, {
|
|
10973
|
+
asOwner: options.asOwner,
|
|
10974
|
+
question: `change ${identity}'s note files as you, the owner?`
|
|
10975
|
+
});
|
|
10976
|
+
if (who !== "owner")
|
|
10977
|
+
by = { bot: who.bot, reason: `files notes links ${operation}` };
|
|
10978
|
+
}
|
|
10979
|
+
const result = await withStore(env, async (store) => {
|
|
10980
|
+
const folders = await boundFolders(store, env, { strict: false });
|
|
10981
|
+
await importNotesMap(store, env, folders);
|
|
10982
|
+
const person = await store.people.personOf(await identityOf(store, identity));
|
|
10983
|
+
if (person === void 0)
|
|
10984
|
+
throw new CliError20("not_found", `the store has no person for "${identity}"`, { reason: "person.not-found" });
|
|
10985
|
+
const to = `person:${person.uid}`;
|
|
10986
|
+
const files = /* @__PURE__ */ __name(async () => {
|
|
10987
|
+
const found = [];
|
|
10988
|
+
for (const link of await store.notes.links({ to })) {
|
|
10989
|
+
if (link.kind !== "about" || link.origin !== "owner")
|
|
10990
|
+
continue;
|
|
10991
|
+
const note = await store.notes.resolveNote(link.from);
|
|
10992
|
+
if (note?.source === "file" && note.deletedAt === null)
|
|
10993
|
+
found.push({ link, note });
|
|
10994
|
+
}
|
|
10995
|
+
return found;
|
|
10996
|
+
}, "files");
|
|
10997
|
+
if (operation === "clear")
|
|
10998
|
+
for (const { link } of await files())
|
|
10999
|
+
await store.notes.removeLink(link.id, by);
|
|
11000
|
+
else if (path !== void 0) {
|
|
11001
|
+
const { folder, path: inside3 } = folderOfFile(folders, path);
|
|
11002
|
+
const note = (await folderNotes(store, folder.id)).find((candidate) => candidate.path === inside3);
|
|
11003
|
+
if (!note)
|
|
11004
|
+
throw new CliError20("not_found", `${path} is not imported yet \u2014 files sync`, {
|
|
11005
|
+
reason: "note.not-imported"
|
|
11006
|
+
});
|
|
11007
|
+
await store.notes.addLink({ from: note.ref, to, kind: "about", origin: "owner", by });
|
|
11008
|
+
}
|
|
11009
|
+
const paths = (await files()).map(({ note }) => {
|
|
11010
|
+
const folder = folders.find((candidate) => candidate.id === note.folderId);
|
|
11011
|
+
return folder ? join9(folder.path, note.path) : note.ref;
|
|
11012
|
+
});
|
|
11013
|
+
return { person: to, name: person.name ?? person.uid, files: paths };
|
|
11014
|
+
});
|
|
11015
|
+
print(options.json, itemAnswer(result), `${result.name}: ${result.files.join(", ") || "no note"}`);
|
|
11016
|
+
});
|
|
11017
|
+
}
|
|
11018
|
+
}, "noteLinksCommand");
|
|
11019
|
+
|
|
11020
|
+
// dist/search.js
|
|
11021
|
+
import { annotate as annotate5 } from "@wirecat/cli-base/commands";
|
|
11022
|
+
import { LOCAL_READ as LOCAL_READ4, noteHitItem, searchNotesOf } from "@wirecat/cli-core";
|
|
10827
11023
|
import { InvalidArgumentError as InvalidArgumentError4 } from "commander";
|
|
10828
11024
|
|
|
10829
11025
|
// dist/notes/search.js
|
|
@@ -10856,7 +11052,7 @@ var notesAnswer = /* @__PURE__ */ __name((found, limit, page, args = {}) => list
|
|
|
10856
11052
|
var searchCommand = /* @__PURE__ */ __name((program, streams, env) => {
|
|
10857
11053
|
const { print } = answers(program, streams, env);
|
|
10858
11054
|
const group = program.command("search").description("search the notes in the local store");
|
|
10859
|
-
|
|
11055
|
+
annotate5(group.command("notes"), { effects: LOCAL_READ4, output: { entity: "note", view: "hit" } }).description("native notes by words and, with the local model, meaning").argument("<query...>", "words, phrases, Boolean operators and field queries").addHelpText("after", "\nsource:internal keeps the notes you wrote with notes add, source:file the notes from a folder \u2014 'budget source:internal'.\n--source notes:<folder id> is different: it chooses which notes accounts are read.\nFields in the query or in --filter (tag:, date:) hold for every hit, found by words or by meaning; a query of\nfields alone lists the matching notes, newest first \u2014 'budget tag:work', 'date:today'.\n--json: each note's reference is ref (note: or document:).").option("--limit <n>", "most results, at most 100", (value) => {
|
|
10860
11056
|
const limit = positive(value);
|
|
10861
11057
|
if (limit > 100)
|
|
10862
11058
|
throw new InvalidArgumentError4("at most 100");
|
|
@@ -10885,17 +11081,16 @@ var searchCommand = /* @__PURE__ */ __name((program, streams, env) => {
|
|
|
10885
11081
|
}, "searchCommand");
|
|
10886
11082
|
|
|
10887
11083
|
// dist/sources/command.js
|
|
10888
|
-
import { existsSync as
|
|
10889
|
-
import { CliError as
|
|
10890
|
-
import { annotate as
|
|
10891
|
-
import { addedSourceKeyOf, environmentOf as environmentOf4, FETCH as FETCH2, LOCAL_READ as
|
|
11084
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
11085
|
+
import { CliError as CliError29 } from "@wirecat/cli-base";
|
|
11086
|
+
import { annotate as annotate7 } from "@wirecat/cli-base/commands";
|
|
11087
|
+
import { addedSourceKeyOf, environmentOf as environmentOf4, FETCH as FETCH2, LOCAL_READ as LOCAL_READ6, LOCAL_WRITE as LOCAL_WRITE6, REMOTE_READ } from "@wirecat/cli-core";
|
|
10892
11088
|
import { agentPictureReader, aiImageReader, MAX_TEXT_CHARS } from "@wirecat/cli-core/documents";
|
|
10893
|
-
import { InvalidArgumentError as InvalidArgumentError5 } from "commander";
|
|
10894
11089
|
|
|
10895
11090
|
// dist/notes/embed.js
|
|
10896
|
-
import { existsSync as
|
|
10897
|
-
import { join as
|
|
10898
|
-
import { isCliError as
|
|
11091
|
+
import { existsSync as existsSync6, readdirSync as readdirSync4 } from "node:fs";
|
|
11092
|
+
import { join as join10 } from "node:path";
|
|
11093
|
+
import { isCliError as isCliError5 } from "@wirecat/cli-base";
|
|
10899
11094
|
import { chosenTextModel, embedNotes as embedNoteChunksOf, sharedModelsDirectory, textModels } from "@wirecat/cli-core";
|
|
10900
11095
|
var EMBED_PER_RUN = 600;
|
|
10901
11096
|
var MEASURED_WITH = "e5-small";
|
|
@@ -10907,19 +11102,19 @@ var embedPerRun = /* @__PURE__ */ __name((env = process.env) => {
|
|
|
10907
11102
|
return Math.max(8, Math.min(EMBED_PER_RUN, Math.round(EMBED_PER_RUN * ratio)));
|
|
10908
11103
|
}, "embedPerRun");
|
|
10909
11104
|
var missingModel = /* @__PURE__ */ __name((error, env) => {
|
|
10910
|
-
const named2 =
|
|
11105
|
+
const named2 = isCliError5(error) ? error.details.model : void 0;
|
|
10911
11106
|
const id = typeof named2 === "string" ? named2 : chosenTextModel(env).id;
|
|
10912
11107
|
return `the ${id} model is not downloaded \u2014 wcat models download ${id}`;
|
|
10913
11108
|
}, "missingModel");
|
|
10914
11109
|
var searchModelPresent = /* @__PURE__ */ __name((env) => {
|
|
10915
11110
|
try {
|
|
10916
|
-
const path =
|
|
10917
|
-
return
|
|
11111
|
+
const path = join10(sharedModelsDirectory("text", env), chosenTextModel(env).id);
|
|
11112
|
+
return existsSync6(path) && readdirSync4(path).length > 0;
|
|
10918
11113
|
} catch {
|
|
10919
11114
|
return false;
|
|
10920
11115
|
}
|
|
10921
11116
|
}, "searchModelPresent");
|
|
10922
|
-
var isMissingModel = /* @__PURE__ */ __name((error) =>
|
|
11117
|
+
var isMissingModel = /* @__PURE__ */ __name((error) => isCliError5(error) && error.details.reason === "model.not-downloaded", "isMissingModel");
|
|
10923
11118
|
var reportOf = /* @__PURE__ */ __name((run2) => {
|
|
10924
11119
|
if (run2 === void 0)
|
|
10925
11120
|
return void 0;
|
|
@@ -10967,7 +11162,7 @@ var embedNoteChunks = /* @__PURE__ */ __name(async (store, { embed = true, env,
|
|
|
10967
11162
|
} catch (error) {
|
|
10968
11163
|
if (!isMissingModel(error))
|
|
10969
11164
|
throw error;
|
|
10970
|
-
const enrichment =
|
|
11165
|
+
const enrichment = isCliError5(error) ? reportOf(error.details.enrichment) : void 0;
|
|
10971
11166
|
return {
|
|
10972
11167
|
chunks: 0,
|
|
10973
11168
|
left: true,
|
|
@@ -10979,14 +11174,14 @@ var embedNoteChunks = /* @__PURE__ */ __name(async (store, { embed = true, env,
|
|
|
10979
11174
|
|
|
10980
11175
|
// dist/sources/copy.js
|
|
10981
11176
|
import { randomUUID } from "node:crypto";
|
|
10982
|
-
import { existsSync as
|
|
10983
|
-
import { isAbsolute, join as
|
|
11177
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync5, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync5 } from "node:fs";
|
|
11178
|
+
import { isAbsolute as isAbsolute2, join as join11, relative as relative5, resolve as resolve5, sep as sep6 } from "node:path";
|
|
10984
11179
|
import { resolvePaths as resolvePaths4 } from "@wirecat/cli-base";
|
|
10985
|
-
var copiesDir = /* @__PURE__ */ __name((env) =>
|
|
10986
|
-
var copyPath = /* @__PURE__ */ __name((env, hash) =>
|
|
11180
|
+
var copiesDir = /* @__PURE__ */ __name((env) => join11(resolvePaths4({ appName: APP.appName, prefix: APP.envPrefix, env }).state, "sources"), "copiesDir");
|
|
11181
|
+
var copyPath = /* @__PURE__ */ __name((env, hash) => join11(copiesDir(env), hash), "copyPath");
|
|
10987
11182
|
var keepCopy = /* @__PURE__ */ __name((env, hash, bytes) => {
|
|
10988
11183
|
const path = copyPath(env, hash);
|
|
10989
|
-
if (
|
|
11184
|
+
if (existsSync7(path))
|
|
10990
11185
|
return { path, wrote: false };
|
|
10991
11186
|
mkdirSync5(copiesDir(env), { recursive: true, mode: 448 });
|
|
10992
11187
|
const partial = `${path}.${randomUUID()}.part`;
|
|
@@ -10995,8 +11190,8 @@ var keepCopy = /* @__PURE__ */ __name((env, hash, bytes) => {
|
|
|
10995
11190
|
return { path, wrote: true };
|
|
10996
11191
|
}, "keepCopy");
|
|
10997
11192
|
var dropCopy = /* @__PURE__ */ __name((env, path) => {
|
|
10998
|
-
const inside3 =
|
|
10999
|
-
if (!inside3 ||
|
|
11193
|
+
const inside3 = relative5(resolve5(copiesDir(env)), resolve5(path));
|
|
11194
|
+
if (!inside3 || isAbsolute2(inside3) || inside3.startsWith("..") || inside3.includes(sep6) || !existsSync7(path))
|
|
11000
11195
|
return false;
|
|
11001
11196
|
rmSync2(path);
|
|
11002
11197
|
return true;
|
|
@@ -11072,15 +11267,15 @@ ${note.text}`);
|
|
|
11072
11267
|
}, "namedIn");
|
|
11073
11268
|
|
|
11074
11269
|
// dist/sources/suggest-command.js
|
|
11075
|
-
import { CliError as
|
|
11076
|
-
import { annotate as
|
|
11270
|
+
import { CliError as CliError28 } from "@wirecat/cli-base";
|
|
11271
|
+
import { annotate as annotate6 } from "@wirecat/cli-base/commands";
|
|
11077
11272
|
import { HOST_PATTERN, hostFetch } from "@wirecat/cli-base/http";
|
|
11078
11273
|
import { defineQuery } from "@wirecat/cli-base/query";
|
|
11079
|
-
import { environmentOf as environmentOf3, FETCH, LOCAL_READ as
|
|
11274
|
+
import { environmentOf as environmentOf3, FETCH, LOCAL_READ as LOCAL_READ5, LOCAL_WRITE as LOCAL_WRITE5, listQuery, nativeTerms, termField as termField2, typedQuery, withQuery as withQuery3 } from "@wirecat/cli-core";
|
|
11080
11275
|
import { aiSettingPath as aiSettingPath2, readAiSetting as readAiSetting2 } from "@wirecat/cli-core/documents";
|
|
11081
11276
|
|
|
11082
11277
|
// dist/sources/readers/ai-model.js
|
|
11083
|
-
import { CliError as
|
|
11278
|
+
import { CliError as CliError21, isCliError as isCliError6 } from "@wirecat/cli-base";
|
|
11084
11279
|
import { aiLeavesComputer, aiSettingPath, aiTextReader, readAiSetting } from "@wirecat/cli-core/documents";
|
|
11085
11280
|
var SET = "wcat models ai set";
|
|
11086
11281
|
var chosen = /* @__PURE__ */ __name((context2) => aiTextReader({
|
|
@@ -11133,21 +11328,21 @@ var aiModel = {
|
|
|
11133
11328
|
read: /* @__PURE__ */ __name(async (context2, { system, prompt }) => {
|
|
11134
11329
|
const found = reader(context2);
|
|
11135
11330
|
if ("refused" in found)
|
|
11136
|
-
throw found.refused === "ai.not-set" ? new
|
|
11331
|
+
throw found.refused === "ai.not-set" ? new CliError21("configuration_error", problemOf(found.refused), { reason: "reader.ai-not-set" }) : new CliError21("authentication_error", problemOf(found.refused), { reason: "reader.no-key" });
|
|
11137
11332
|
try {
|
|
11138
11333
|
return await found.complete({ purpose: "sources", system, prompt, maxTokens: 4096 });
|
|
11139
11334
|
} catch (error) {
|
|
11140
|
-
if (
|
|
11141
|
-
throw new
|
|
11335
|
+
if (isCliError6(error) && error.code === "rate_limited")
|
|
11336
|
+
throw new CliError21("rate_limited", `${found.by} says the limit is reached; try later`, {
|
|
11142
11337
|
reason: "reader.limit"
|
|
11143
11338
|
});
|
|
11144
|
-
throw new
|
|
11339
|
+
throw new CliError21("invalid_response", `${found.by} failed: wcat models ai check names the cause (key, model, credit or address)`, { reason: "reader.failed" });
|
|
11145
11340
|
}
|
|
11146
11341
|
}, "read")
|
|
11147
11342
|
};
|
|
11148
11343
|
|
|
11149
11344
|
// dist/sources/readers/api.js
|
|
11150
|
-
import { CliError as
|
|
11345
|
+
import { CliError as CliError22, isCliError as isCliError7 } from "@wirecat/cli-base";
|
|
11151
11346
|
import { modelGateway } from "@wirecat/cli-core";
|
|
11152
11347
|
|
|
11153
11348
|
// dist/sources/readers/keys.js
|
|
@@ -11195,7 +11390,7 @@ var apiReader = /* @__PURE__ */ __name((provider, title) => ({
|
|
|
11195
11390
|
read: /* @__PURE__ */ __name(async (context2, { system, prompt, model }) => {
|
|
11196
11391
|
const key = providerKeys(context2).read(provider);
|
|
11197
11392
|
if (key === void 0)
|
|
11198
|
-
throw new
|
|
11393
|
+
throw new CliError22("authentication_error", `no ${title} key: wcat models ai set ${provider} --secret-stdin`, {
|
|
11199
11394
|
reason: "reader.no-key"
|
|
11200
11395
|
});
|
|
11201
11396
|
const gateway = modelGateway({
|
|
@@ -11209,9 +11404,9 @@ var apiReader = /* @__PURE__ */ __name((provider, title) => ({
|
|
|
11209
11404
|
try {
|
|
11210
11405
|
return (await gateway.complete({ purpose: "sources", system, prompt, maxTokens: 4096 })).text;
|
|
11211
11406
|
} catch (error) {
|
|
11212
|
-
if (
|
|
11213
|
-
throw new
|
|
11214
|
-
throw new
|
|
11407
|
+
if (isCliError7(error) && error.code === "rate_limited")
|
|
11408
|
+
throw new CliError22("rate_limited", `${title} says the limit is reached; try later`, { reason: "reader.limit" });
|
|
11409
|
+
throw new CliError22("invalid_response", `${title} failed: check the key (wcat models ai set ${provider} --secret-stdin), the model and the account's credit`, { reason: "reader.failed" });
|
|
11215
11410
|
}
|
|
11216
11411
|
}, "read")
|
|
11217
11412
|
}), "apiReader");
|
|
@@ -11221,12 +11416,12 @@ var anthropicReader = apiReader("anthropic", "Anthropic");
|
|
|
11221
11416
|
// dist/sources/readers/claude-code.js
|
|
11222
11417
|
import { mkdtempSync, rmSync as rmSync3 } from "node:fs";
|
|
11223
11418
|
import { tmpdir } from "node:os";
|
|
11224
|
-
import { join as
|
|
11225
|
-
import { CliError as
|
|
11419
|
+
import { join as join12 } from "node:path";
|
|
11420
|
+
import { CliError as CliError24 } from "@wirecat/cli-base";
|
|
11226
11421
|
|
|
11227
11422
|
// dist/sources/readers/process.js
|
|
11228
11423
|
import { spawn } from "node:child_process";
|
|
11229
|
-
import { CliError as
|
|
11424
|
+
import { CliError as CliError23 } from "@wirecat/cli-base";
|
|
11230
11425
|
var TIMEOUT_MS = 6e5;
|
|
11231
11426
|
var MAX_OUTPUT = 4 * 1024 * 1024;
|
|
11232
11427
|
var WITHHELD = ["ANTHROPIC_API_KEY", "OPENAI_API_KEY", "CLAUDECODE", "AI_AGENT"];
|
|
@@ -11251,14 +11446,14 @@ var runProgram = /* @__PURE__ */ __name((program, args, { env, cwd, stdin, signa
|
|
|
11251
11446
|
if (error.code === "ENOENT")
|
|
11252
11447
|
resolve6(void 0);
|
|
11253
11448
|
else if (error.name === "AbortError")
|
|
11254
|
-
reject(new
|
|
11449
|
+
reject(new CliError23("cancelled", `${program} was stopped`));
|
|
11255
11450
|
else
|
|
11256
11451
|
reject(error);
|
|
11257
11452
|
});
|
|
11258
11453
|
child.on("close", (code, killed) => {
|
|
11259
11454
|
clearTimeout(timer);
|
|
11260
11455
|
if (killed === "SIGTERM" && code === null)
|
|
11261
|
-
return reject(new
|
|
11456
|
+
return reject(new CliError23("timeout", `${program} gave no answer in time, or too long an answer`, {
|
|
11262
11457
|
reason: "reader.timeout"
|
|
11263
11458
|
}));
|
|
11264
11459
|
resolve6({ code, stdout: Buffer.concat(out).toString("utf8"), stderr: Buffer.concat(err).toString("utf8") });
|
|
@@ -11302,7 +11497,7 @@ var claudeCode = {
|
|
|
11302
11497
|
};
|
|
11303
11498
|
}, "probe"),
|
|
11304
11499
|
read: /* @__PURE__ */ __name(async ({ env, signal }, { system, prompt, model }) => {
|
|
11305
|
-
const folder = mkdtempSync(
|
|
11500
|
+
const folder = mkdtempSync(join12(tmpdir(), "files-reader-"));
|
|
11306
11501
|
try {
|
|
11307
11502
|
const ran = await runProgram("claude", [
|
|
11308
11503
|
"--print",
|
|
@@ -11322,9 +11517,9 @@ var claudeCode = {
|
|
|
11322
11517
|
...model ? ["--model", model] : []
|
|
11323
11518
|
], { env, cwd: folder, stdin: prompt, ...signal ? { signal } : {} });
|
|
11324
11519
|
if (!ran)
|
|
11325
|
-
throw new
|
|
11520
|
+
throw new CliError24("configuration_error", "Claude Code is not installed", { reason: "reader.unavailable" });
|
|
11326
11521
|
if (ran.code !== 0)
|
|
11327
|
-
throw new
|
|
11522
|
+
throw new CliError24("invalid_response", `Claude Code failed: ${firstLine2(ran.stderr || ran.stdout)}`, {
|
|
11328
11523
|
reason: "reader.failed"
|
|
11329
11524
|
});
|
|
11330
11525
|
return ran.stdout;
|
|
@@ -11337,8 +11532,8 @@ var claudeCode = {
|
|
|
11337
11532
|
// dist/sources/readers/codex.js
|
|
11338
11533
|
import { mkdtempSync as mkdtempSync2, readFileSync as readFileSync6, rmSync as rmSync4 } from "node:fs";
|
|
11339
11534
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
11340
|
-
import { join as
|
|
11341
|
-
import { CliError as
|
|
11535
|
+
import { join as join13 } from "node:path";
|
|
11536
|
+
import { CliError as CliError25 } from "@wirecat/cli-base";
|
|
11342
11537
|
var codex = {
|
|
11343
11538
|
id: "codex",
|
|
11344
11539
|
title: "Codex CLI",
|
|
@@ -11361,8 +11556,8 @@ var codex = {
|
|
|
11361
11556
|
};
|
|
11362
11557
|
}, "probe"),
|
|
11363
11558
|
read: /* @__PURE__ */ __name(async ({ env, signal }, { system, prompt, model }) => {
|
|
11364
|
-
const folder = mkdtempSync2(
|
|
11365
|
-
const answer =
|
|
11559
|
+
const folder = mkdtempSync2(join13(tmpdir2(), "files-reader-"));
|
|
11560
|
+
const answer = join13(folder, "answer.txt");
|
|
11366
11561
|
try {
|
|
11367
11562
|
const ran = await runProgram(
|
|
11368
11563
|
"codex",
|
|
@@ -11389,9 +11584,9 @@ var codex = {
|
|
|
11389
11584
|
${prompt}`, ...signal ? { signal } : {} }
|
|
11390
11585
|
);
|
|
11391
11586
|
if (!ran)
|
|
11392
|
-
throw new
|
|
11587
|
+
throw new CliError25("configuration_error", "Codex CLI is not installed", { reason: "reader.unavailable" });
|
|
11393
11588
|
if (ran.code !== 0)
|
|
11394
|
-
throw new
|
|
11589
|
+
throw new CliError25("invalid_response", `Codex CLI failed: ${firstLine2(ran.stderr || ran.stdout)}`, {
|
|
11395
11590
|
reason: "reader.failed"
|
|
11396
11591
|
});
|
|
11397
11592
|
try {
|
|
@@ -11406,7 +11601,7 @@ ${prompt}`, ...signal ? { signal } : {} }
|
|
|
11406
11601
|
};
|
|
11407
11602
|
|
|
11408
11603
|
// dist/sources/readers/ollama.js
|
|
11409
|
-
import { CliError as
|
|
11604
|
+
import { CliError as CliError26 } from "@wirecat/cli-base";
|
|
11410
11605
|
import { onThisComputer as onThisComputer2 } from "@wirecat/cli-core";
|
|
11411
11606
|
var OLLAMA = "http://127.0.0.1:11434";
|
|
11412
11607
|
var ollamaAddressAllowed = /* @__PURE__ */ __name((value) => {
|
|
@@ -11424,12 +11619,12 @@ var addressOf = /* @__PURE__ */ __name((env) => {
|
|
|
11424
11619
|
if (given === void 0)
|
|
11425
11620
|
return OLLAMA;
|
|
11426
11621
|
if (!ollamaAddressAllowed(given))
|
|
11427
|
-
throw new
|
|
11622
|
+
throw new CliError26("configuration_error", `sources.base_url ${given} is not on this computer`, {
|
|
11428
11623
|
reason: "reader.address-refused"
|
|
11429
11624
|
});
|
|
11430
11625
|
return given.replace(/\/+$/, "");
|
|
11431
11626
|
}, "addressOf");
|
|
11432
|
-
var notRunning = /* @__PURE__ */ __name(() => new
|
|
11627
|
+
var notRunning = /* @__PURE__ */ __name(() => new CliError26("provider_unavailable", "Ollama is not running on this computer: start it with ollama serve", {
|
|
11433
11628
|
reason: "reader.not-running"
|
|
11434
11629
|
}), "notRunning");
|
|
11435
11630
|
var ollama = {
|
|
@@ -11475,12 +11670,12 @@ var ollama = {
|
|
|
11475
11670
|
throw notRunning();
|
|
11476
11671
|
}
|
|
11477
11672
|
if (response.status === 404)
|
|
11478
|
-
throw new
|
|
11673
|
+
throw new CliError26("not_found", `Ollama has no model ${model}: ollama pull ${model}`, {
|
|
11479
11674
|
reason: "reader.model-missing"
|
|
11480
11675
|
});
|
|
11481
11676
|
const body = await response.json().catch(() => ({}));
|
|
11482
11677
|
if (!response.ok || typeof body.response !== "string")
|
|
11483
|
-
throw new
|
|
11678
|
+
throw new CliError26("invalid_response", `Ollama answered ${response.status}`, { reason: "reader.failed" });
|
|
11484
11679
|
return body.response;
|
|
11485
11680
|
}, "read")
|
|
11486
11681
|
};
|
|
@@ -11495,7 +11690,7 @@ var readerOf2 = /* @__PURE__ */ __name((id) => READERS.find((reader2) => reader2
|
|
|
11495
11690
|
|
|
11496
11691
|
// dist/sources/suggest.js
|
|
11497
11692
|
import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
|
|
11498
|
-
import { CliError as
|
|
11693
|
+
import { CliError as CliError27 } from "@wirecat/cli-base";
|
|
11499
11694
|
import { FACT_TYPES, QUOTE_LIMIT, quoteKept } from "@wirecat/cli-core";
|
|
11500
11695
|
var PROMPT_VERSION = "facts-1";
|
|
11501
11696
|
var READER_BOT = "files-reader";
|
|
@@ -11527,7 +11722,7 @@ var objectIn = /* @__PURE__ */ __name((answer) => {
|
|
|
11527
11722
|
var factsIn = /* @__PURE__ */ __name((answer, text2) => {
|
|
11528
11723
|
const body = objectIn(answer);
|
|
11529
11724
|
if (!body || !Array.isArray(body.facts))
|
|
11530
|
-
throw new
|
|
11725
|
+
throw new CliError27("invalid_response", "the reader's answer was not the JSON files asked for; nothing was staged", {
|
|
11531
11726
|
reason: "reader.unusable-answer"
|
|
11532
11727
|
});
|
|
11533
11728
|
const facts = [];
|
|
@@ -11653,25 +11848,25 @@ var readerHosts = /* @__PURE__ */ __name((env) => {
|
|
|
11653
11848
|
var READ_TIMEOUT_MS = 15 * 6e4;
|
|
11654
11849
|
var isAgentServer = /* @__PURE__ */ __name((command, _env) => environmentOf3(command).agent !== void 0, "isAgentServer");
|
|
11655
11850
|
var unknownReader = /* @__PURE__ */ __name((id) => {
|
|
11656
|
-
throw new
|
|
11851
|
+
throw new CliError28("validation_error", `${id} is not a reader files knows; it reads with ${READER_IDS.join(", ")}`, {
|
|
11657
11852
|
reason: "reader.unknown",
|
|
11658
11853
|
reader: id,
|
|
11659
11854
|
readers: READER_IDS
|
|
11660
11855
|
});
|
|
11661
11856
|
}, "unknownReader");
|
|
11662
|
-
var fixedModel = /* @__PURE__ */ __name((reader2) => new
|
|
11857
|
+
var fixedModel = /* @__PURE__ */ __name((reader2) => new CliError28("validation_error", `${reader2.title} reads with the model wcat models ai set chose; --model is not taken`, {
|
|
11663
11858
|
reason: "input.invalid",
|
|
11664
11859
|
param: "model"
|
|
11665
11860
|
}), "fixedModel");
|
|
11666
11861
|
var chosen2 = /* @__PURE__ */ __name((env, who, given) => {
|
|
11667
11862
|
if (who !== "owner" && (given.reader !== void 0 || given.model !== void 0))
|
|
11668
|
-
throw new
|
|
11863
|
+
throw new CliError28("permission_error", "only the owner picks the reader; an agent uses the one the owner chose", {
|
|
11669
11864
|
reason: "reader.owner-picks"
|
|
11670
11865
|
});
|
|
11671
11866
|
const config = loadConfig(env).sources;
|
|
11672
11867
|
const id = given.reader ?? config?.reader;
|
|
11673
11868
|
if (id === void 0)
|
|
11674
|
-
throw new
|
|
11869
|
+
throw new CliError28("configuration_error", `no reader is chosen for sources; the owner picks one of ${READER_IDS.join(", ")} with files sources readers set <reader>, or names it with --provider`, { reason: "reader.none-chosen", readers: READER_IDS });
|
|
11675
11870
|
const reader2 = readerOf2(id) ?? unknownReader(id);
|
|
11676
11871
|
if (reader2.modelOf) {
|
|
11677
11872
|
if (given.model !== void 0)
|
|
@@ -11680,14 +11875,14 @@ var chosen2 = /* @__PURE__ */ __name((env, who, given) => {
|
|
|
11680
11875
|
}
|
|
11681
11876
|
const model = given.model ?? (given.reader === void 0 || given.reader === config?.reader ? config?.model : void 0);
|
|
11682
11877
|
if (reader2.needsModel && !model)
|
|
11683
|
-
throw new
|
|
11878
|
+
throw new CliError28("configuration_error", `${reader2.title} reads only with a model the owner names: files sources readers set ${reader2.id} --model <model>`, { reason: "reader.model-missing" });
|
|
11684
11879
|
return { reader: reader2, model: model ?? null };
|
|
11685
11880
|
}, "chosen");
|
|
11686
11881
|
var documentRef = /* @__PURE__ */ __name(async (store, reference) => {
|
|
11687
11882
|
await refuseBareNumber(store, reference, ["document", "note"]);
|
|
11688
11883
|
const ref = reference.trim();
|
|
11689
11884
|
if (!/^(document|note):[1-9]\d*$/.test(ref))
|
|
11690
|
-
throw new
|
|
11885
|
+
throw new CliError28("validation_error", `${reference} is not a source; give its document:<id>`, {
|
|
11691
11886
|
reason: "input.invalid"
|
|
11692
11887
|
});
|
|
11693
11888
|
return ref;
|
|
@@ -11703,22 +11898,22 @@ var readerCommands = /* @__PURE__ */ __name((program, sources, streams, env, dep
|
|
|
11703
11898
|
}),
|
|
11704
11899
|
...deps.keyring ? { keyring: deps.keyring } : {}
|
|
11705
11900
|
}), "context");
|
|
11706
|
-
byOption(
|
|
11901
|
+
byOption(annotate6(sources.command("suggest"), { effects: FETCH, output: { entity: "source_suggestion" } }).summary("have the chosen reader propose facts from a source, for you to confirm").description("send a source's text to the reader you chose and stage the facts it finds, each with a quote checked against the text, as one batch only you confirm")).argument("<ref>", "document:<id> of the source, as sources add answered").option("--provider <provider>", `read with this reader once: ${READER_IDS.join(", ")}; only you name one`).option("--model <model>", "the reader's model this once; only you may name one").option("--subject <ref>", "who or what every fact is about: person:, organization:, project: or task:").option("--rescan", "read it again although this reader already read this text").action(async (reference, options, command) => {
|
|
11707
11902
|
if (isAgentServer(command, env))
|
|
11708
|
-
throw new
|
|
11903
|
+
throw new CliError28("permission_error", "over MCP an agent cannot send a source's text to a reader");
|
|
11709
11904
|
const who = await whoRuns(command, env, { asOwner: options.asOwner, question: "read this source as you?" });
|
|
11710
11905
|
const { reader: reader2, model } = chosen2(env, who, { reader: options.provider, model: options.model });
|
|
11711
11906
|
const item = await withStore(env, async (store) => {
|
|
11712
11907
|
const ref = await documentRef(store, reference);
|
|
11713
11908
|
const subject = options.subject === void 0 ? null : (await subjectOf(store, options.subject)).ref;
|
|
11714
11909
|
if (subject !== null && !SUBJECT.test(subject))
|
|
11715
|
-
throw new
|
|
11910
|
+
throw new CliError28("validation_error", "a suggested fact is about a person:, organization:, project: or task:", {
|
|
11716
11911
|
reason: "input.invalid",
|
|
11717
11912
|
param: "subject"
|
|
11718
11913
|
});
|
|
11719
11914
|
const record2 = await store.evidenceFindings.citable(ref);
|
|
11720
11915
|
if (!record2)
|
|
11721
|
-
throw new
|
|
11916
|
+
throw new CliError28("not_found", `${ref} is not stored`, { reason: "input.invalid" });
|
|
11722
11917
|
const done = await suggestFacts(store, context2(), {
|
|
11723
11918
|
record: record2,
|
|
11724
11919
|
reader: reader2,
|
|
@@ -11755,8 +11950,8 @@ var readerCommands = /* @__PURE__ */ __name((program, sources, streams, env, dep
|
|
|
11755
11950
|
].join("\n"));
|
|
11756
11951
|
});
|
|
11757
11952
|
const readers = sources.command("readers").summary("the readers that can propose facts from a source, and which one you chose").description("the readers that can propose facts from a source: installed, signed in, and which one you chose");
|
|
11758
|
-
withQuery3(
|
|
11759
|
-
effects:
|
|
11953
|
+
withQuery3(annotate6(readers.command("list", { isDefault: true }), {
|
|
11954
|
+
effects: LOCAL_READ5,
|
|
11760
11955
|
output: { entity: "source_reader" }
|
|
11761
11956
|
}), READERS_QUERY).summary("each reader: installed, signed in, and your pick").description("each reader: installed, signed in, its model, whether the text leaves this computer, and your pick").action(async (words, options) => {
|
|
11762
11957
|
const terms = nativeTerms(listQuery(typedQuery(words), READERS_QUERY, "sources readers list"), "sources readers list");
|
|
@@ -11785,27 +11980,27 @@ var readerCommands = /* @__PURE__ */ __name((program, sources, streams, env, dep
|
|
|
11785
11980
|
const items = all.filter((item) => (flag("available") === void 0 || String(item.available) === flag("available")) && (flag("chosen") === void 0 || String(item.chosen) === flag("chosen")));
|
|
11786
11981
|
print(options.json, listAnswer("sources readers list", { items, limit: Math.max(1, items.length), has_more: false }), items.map((item) => `${item.chosen ? "*" : " "} ${item.id.padEnd(12)} ${item.problem ?? "ready"}${item.model ? ` model ${item.model}` : ""}${item.leavesComputer ? "" : " stays on this computer"}`).join("\n"));
|
|
11787
11982
|
});
|
|
11788
|
-
byOption(
|
|
11983
|
+
byOption(annotate6(readers.command("set"), { effects: LOCAL_WRITE5, output: { entity: "source_reader_choice" } }).summary("choose the reader that reads your sources").description("choose the reader sources suggest sends a source's text to, and its model; only you choose")).argument("<reader>", READER_IDS.join(", ")).option("--model <model>", "its model; Ollama and the API readers need one, Claude Code and Codex use their own").option("--base-url <url>", `Ollama only: its address on this computer, when not ${OLLAMA}`).action(async (id, options, command) => {
|
|
11789
11984
|
if (isAgentServer(command, env))
|
|
11790
|
-
throw new
|
|
11985
|
+
throw new CliError28("permission_error", "only the owner picks the reader", { reason: "reader.owner-picks" });
|
|
11791
11986
|
const who = await whoRuns(command, env, { asOwner: options.asOwner, question: `read sources with ${id}?` });
|
|
11792
11987
|
if (who !== "owner")
|
|
11793
|
-
throw new
|
|
11988
|
+
throw new CliError28("permission_error", "only the owner picks the reader that reads a source", {
|
|
11794
11989
|
reason: "reader.owner-picks"
|
|
11795
11990
|
});
|
|
11796
11991
|
const reader2 = readerOf2(id) ?? unknownReader(id);
|
|
11797
11992
|
if (reader2.modelOf && options.model !== void 0)
|
|
11798
11993
|
throw fixedModel(reader2);
|
|
11799
11994
|
if (reader2.needsModel && !options.model?.trim())
|
|
11800
|
-
throw new
|
|
11995
|
+
throw new CliError28("validation_error", `${reader2.title} needs --model <model>`, {
|
|
11801
11996
|
reason: "reader.model-missing",
|
|
11802
11997
|
param: "model"
|
|
11803
11998
|
});
|
|
11804
11999
|
const baseUrl = options.baseUrl?.trim().replace(/\/+$/, "") || void 0;
|
|
11805
12000
|
if (baseUrl !== void 0 && reader2.id !== ollama.id)
|
|
11806
|
-
throw new
|
|
12001
|
+
throw new CliError28("validation_error", "--base-url is for the ollama reader", { param: "base-url" });
|
|
11807
12002
|
if (baseUrl !== void 0 && !ollamaAddressAllowed(baseUrl))
|
|
11808
|
-
throw new
|
|
12003
|
+
throw new CliError28("validation_error", "Ollama is read only on this computer: give http://127.0.0.1:<port>", {
|
|
11809
12004
|
reason: "reader.address-refused",
|
|
11810
12005
|
param: "base-url"
|
|
11811
12006
|
});
|
|
@@ -11828,12 +12023,6 @@ var readerCommands = /* @__PURE__ */ __name((program, sources, streams, env, dep
|
|
|
11828
12023
|
var SUBJECT_HELP = "who or what it is about: person:, organization:, project:, task:, meeting:, or <messenger>:<name or id>; repeat for more";
|
|
11829
12024
|
var TEXT_BYTES = 16384;
|
|
11830
12025
|
var MAX_TEXT_BYTES = 1048576;
|
|
11831
|
-
var between = /* @__PURE__ */ __name((low, high, what) => (value) => {
|
|
11832
|
-
const number = Number(value);
|
|
11833
|
-
if (!Number.isInteger(number) || number < low || number > high)
|
|
11834
|
-
throw new InvalidArgumentError5(`${what}: a whole number, ${low} to ${high}`);
|
|
11835
|
-
return number;
|
|
11836
|
-
}, "between");
|
|
11837
12026
|
var boundedText = /* @__PURE__ */ __name((text2, bytes) => {
|
|
11838
12027
|
const encoded = Buffer.from(text2);
|
|
11839
12028
|
if (encoded.byteLength <= bytes)
|
|
@@ -11847,7 +12036,7 @@ var documentRef2 = /* @__PURE__ */ __name(async (store, reference) => {
|
|
|
11847
12036
|
await refuseBareNumber(store, reference, ["document"]);
|
|
11848
12037
|
const ref = reference.trim();
|
|
11849
12038
|
if (!/^document:[1-9]\d*$/.test(ref))
|
|
11850
|
-
throw new
|
|
12039
|
+
throw new CliError29("validation_error", `${reference} is not a source; give its document:<id>`, {
|
|
11851
12040
|
reason: "input.invalid"
|
|
11852
12041
|
});
|
|
11853
12042
|
return ref;
|
|
@@ -11885,12 +12074,12 @@ var imageLine = /* @__PURE__ */ __name((image) => image.read_by ? `read by ${ima
|
|
|
11885
12074
|
var sourcesCommand = /* @__PURE__ */ __name((program, streams, env, { fetch, readers = {} } = {}) => {
|
|
11886
12075
|
const { print, run: run2 } = answers(program, streams, env);
|
|
11887
12076
|
const sources = program.command("sources").summary("files, web pages and text you add by hand").description("sources you add by hand: pasted text, a file or a web page, kept as searchable documents");
|
|
11888
|
-
byOption(reasonOption(
|
|
12077
|
+
byOption(reasonOption(annotate7(sources.command("add"), { effects: FETCH2, output: { entity: "added_source" } }).summary("keep a file, a web page or pasted text as a document").description("keep a file, a web page or pasted text as a document of its own; only its text is kept unless --keep-copy"))).argument("<source>", "a file's path, an http(s) address, or - to read the text from stdin").option("--title <title>", "a title; otherwise the page's or file's own, or the text's first line").option("--subject <ref>", SUBJECT_HELP, collect).option("--keep-copy", "also keep a copy of the file in files' data folder, so it opens after the file is gone").option("--max-chars <n>", `most characters of text to keep, up to ${MAX_TEXT_CHARS} (default ${SOURCE_TEXT_CHARS})`, between(1, MAX_TEXT_CHARS, "--max-chars")).action(async (given, options, command) => {
|
|
11889
12078
|
const kind = argumentKind(given);
|
|
11890
12079
|
if (isAgentServer2(command, env) && kind !== "text")
|
|
11891
|
-
throw new
|
|
12080
|
+
throw new CliError29("permission_error", "over MCP a source is added as text only, never from a path or a link");
|
|
11892
12081
|
if (options.keepCopy && kind !== "path")
|
|
11893
|
-
throw new
|
|
12082
|
+
throw new CliError29("validation_error", "--keep-copy keeps a file; a link or pasted text keeps its text only", {
|
|
11894
12083
|
reason: "input.invalid",
|
|
11895
12084
|
param: "keep_copy"
|
|
11896
12085
|
});
|
|
@@ -11978,13 +12167,13 @@ var sourcesCommand = /* @__PURE__ */ __name((program, streams, env, { fetch, rea
|
|
|
11978
12167
|
...item.subjects.length ? [` about: ${item.subjects.join(", ")}`] : []
|
|
11979
12168
|
].join("\n"));
|
|
11980
12169
|
});
|
|
11981
|
-
|
|
12170
|
+
annotate7(sources.command("preview"), { effects: REMOTE_READ, output: { entity: "source_preview" } }).summary("read a web page as sources add would, and keep nothing").description("read a web page as sources add would, with the same refusals, and say what would be kept; nothing is saved").argument("<url>", "an http(s) address").action(async (given, options, command) => {
|
|
11982
12171
|
if (isAgentServer2(command, env))
|
|
11983
|
-
throw new
|
|
12172
|
+
throw new CliError29("permission_error", "an agent over MCP cannot make files fetch an address", {
|
|
11984
12173
|
reason: "source.agent-fetch"
|
|
11985
12174
|
});
|
|
11986
12175
|
if (argumentKind(given) !== "url")
|
|
11987
|
-
throw new
|
|
12176
|
+
throw new CliError29("validation_error", "give an http(s) address; a file is previewed by the app that picked it", {
|
|
11988
12177
|
reason: "input.invalid"
|
|
11989
12178
|
});
|
|
11990
12179
|
const read = await readPage(given, { maxChars: SOURCE_TEXT_CHARS, ...fetch ? { fetch } : {} }).catch((error) => {
|
|
@@ -11998,7 +12187,7 @@ var sourcesCommand = /* @__PURE__ */ __name((program, streams, env, { fetch, rea
|
|
|
11998
12187
|
...item.excerpt ? [` \u201C${item.excerpt}\u201D`] : []
|
|
11999
12188
|
].join("\n"));
|
|
12000
12189
|
});
|
|
12001
|
-
|
|
12190
|
+
annotate7(sources.command("show"), { effects: LOCAL_READ6, output: { entity: "source_detail" } }).summary("one source: its text, what is kept, and what cites it").description("one source: its text, what is kept, what it is about, and the facts, memories and batches citing it").argument("<ref>", "document:<id>, as sources add answered").option("--bytes <bytes>", `most UTF-8 bytes of its text, up to ${MAX_TEXT_BYTES} (default ${TEXT_BYTES})`, between(1, MAX_TEXT_BYTES, "--bytes")).action((reference, options) => run2(options.json, async (store) => {
|
|
12002
12191
|
const ref = await documentRef2(store, reference);
|
|
12003
12192
|
const source = await store.notes.addedSource(ref);
|
|
12004
12193
|
const note = source?.note ?? await store.notes.note(ref);
|
|
@@ -12014,7 +12203,7 @@ var sourcesCommand = /* @__PURE__ */ __name((program, streams, env, { fetch, rea
|
|
|
12014
12203
|
mime: source?.mime ?? null,
|
|
12015
12204
|
bytes: source?.size ?? null,
|
|
12016
12205
|
// The row says a copy was kept; only the file itself says it still is.
|
|
12017
|
-
kept: source === void 0 ? null : source.copy !== null &&
|
|
12206
|
+
kept: source === void 0 ? null : source.copy !== null && existsSync8(source.copy) ? "copy" : "text",
|
|
12018
12207
|
chars: note.text.length,
|
|
12019
12208
|
text: text2,
|
|
12020
12209
|
textTruncated: truncated,
|
|
@@ -12025,7 +12214,7 @@ var sourcesCommand = /* @__PURE__ */ __name((program, streams, env, { fetch, rea
|
|
|
12025
12214
|
batches: await batchesCiting(store, ref)
|
|
12026
12215
|
});
|
|
12027
12216
|
}));
|
|
12028
|
-
|
|
12217
|
+
annotate7(sources.command("mentions"), { effects: LOCAL_READ6, output: { entity: "source_mention" } }).summary("known people and organizations named in a source").description("people and organizations files knows whose names appear in a source's text; nothing leaves").argument("<ref>", "document:<id>").action((reference, options) => run2(options.json, async (store) => {
|
|
12029
12218
|
const ref = await documentRef2(store, reference);
|
|
12030
12219
|
const found = await namedIn(store, await store.notes.note(ref));
|
|
12031
12220
|
return listAnswer("sources mentions", {
|
|
@@ -12042,7 +12231,7 @@ var sourcesCommand = /* @__PURE__ */ __name((program, streams, env, { fetch, rea
|
|
|
12042
12231
|
}
|
|
12043
12232
|
});
|
|
12044
12233
|
}));
|
|
12045
|
-
byOption(
|
|
12234
|
+
byOption(annotate7(sources.command("remove"), { effects: LOCAL_WRITE6, output: { entity: "source_removal" } }).summary("remove a source you added, and its kept copy").description("remove a source you added, and its copy if one was kept; the next source check reviews what cites it")).argument("<ref>", "document:<id> of a source you added").action(async (reference, options, command) => {
|
|
12046
12235
|
const who = await whoRuns(command, env, { asOwner: options.asOwner, question: "remove this source as you?" });
|
|
12047
12236
|
const by = who === "owner" ? "owner" : { bot: who.bot, reason: "files sources remove" };
|
|
12048
12237
|
await run2(options.json, async (store) => {
|
|
@@ -12062,23 +12251,23 @@ var sourcesCommand = /* @__PURE__ */ __name((program, streams, env, { fetch, rea
|
|
|
12062
12251
|
|
|
12063
12252
|
// dist/sync.js
|
|
12064
12253
|
import { errorCodes } from "@wirecat/cli-base";
|
|
12065
|
-
import { annotate as
|
|
12254
|
+
import { annotate as annotate8 } from "@wirecat/cli-base/commands";
|
|
12066
12255
|
import { environmentOf as environmentOf5, FETCH as FETCH3, markStoreDamaged, notLocalPaths as notLocalPaths2, openStore as openStore2, setExitCode, storePath } from "@wirecat/cli-core";
|
|
12067
|
-
import { attachmentMaxBytes as attachmentMaxBytes4, sizeText as sizeText3 } from "@wirecat/cli-core/documents";
|
|
12256
|
+
import { attachmentMaxBytes as attachmentMaxBytes4, scanReader, sizeText as sizeText3 } from "@wirecat/cli-core/documents";
|
|
12068
12257
|
import { Option } from "commander";
|
|
12069
12258
|
|
|
12070
12259
|
// dist/failure.js
|
|
12071
|
-
import { CliError as
|
|
12260
|
+
import { CliError as CliError30, errorObjectOf } from "@wirecat/cli-base";
|
|
12072
12261
|
import { failureContext, storeDamaged } from "@wirecat/cli-core";
|
|
12073
12262
|
import { CommanderError } from "commander";
|
|
12074
12263
|
var context = failureContext(APP.errors ?? { reasons: [] });
|
|
12075
12264
|
var recognisable = /* @__PURE__ */ __name((error) => {
|
|
12076
12265
|
if (error instanceof CommanderError)
|
|
12077
|
-
return new
|
|
12266
|
+
return new CliError30("validation_error", error.message.replace(/^error: /, ""), { reason: "input.invalid" });
|
|
12078
12267
|
if (error instanceof ValiError) {
|
|
12079
12268
|
const [issue] = error.issues;
|
|
12080
12269
|
const param = issue?.path?.map((item) => String(item.key)).join(".");
|
|
12081
|
-
return new
|
|
12270
|
+
return new CliError30("validation_error", issue?.message ?? "the input is not valid", {
|
|
12082
12271
|
reason: "input.invalid",
|
|
12083
12272
|
...param ? { param } : {}
|
|
12084
12273
|
});
|
|
@@ -12110,14 +12299,18 @@ var NOT_READ = {
|
|
|
12110
12299
|
"needs-agent": "no text in it, such as a scanned PDF",
|
|
12111
12300
|
unreadable: "the file is damaged or locked"
|
|
12112
12301
|
};
|
|
12113
|
-
var notReadReason = /* @__PURE__ */ __name((status, engine) => status === "engine-missing" ? `needs the ${engine ?? "missing"} reader` : status === "too-large" ? `larger than ${sizeText3(attachmentMaxBytes4())}; configure MESSAGING_ATTACHMENT_MAX_MIB` : NOT_READ[status] ?? status, "notReadReason");
|
|
12302
|
+
var notReadReason = /* @__PURE__ */ __name((status, engine, reason) => reason !== void 0 ? reason : status === "engine-missing" ? `needs the ${engine ?? "missing"} reader` : status === "too-large" ? `larger than ${sizeText3(attachmentMaxBytes4())}; configure MESSAGING_ATTACHMENT_MAX_MIB` : NOT_READ[status] ?? status, "notReadReason");
|
|
12114
12303
|
var enrichmentLine = /* @__PURE__ */ __name((run2) => `enrichment: ${run2.enriched} of ${run2.sent} records sent${run2.provider ? ` to ${run2.provider} ${run2.model}` : ""}` + (run2.costUsd === null ? "" : `, $${run2.costUsd}`) + (run2.left > 0 ? `, ${run2.left} left` : "") + (run2.status === "done" ? "" : ` \u2014 ${run2.status}: ${run2.reason ?? "no reason given"}`), "enrichmentLine");
|
|
12115
12304
|
var text = /* @__PURE__ */ __name((run2) => [
|
|
12116
12305
|
...run2.notes.flatMap((n) => [
|
|
12117
12306
|
`notes ${n.folder}: ${n.notes} notes, ${n.changed} changed, ${n.renamed} moved, ${n.deleted} gone` + (n.notRead ? `, ${n.notRead.length} not read` : "") + (n.deletionsSkipped === void 0 ? "" : ` \u2014 deletions skipped: ${n.deletionsSkipped}`),
|
|
12118
|
-
...(n.notRead ?? []).slice(0, NOT_READ_SHOWN).map(({ path, status, engine }) => ` not read: ${path} \u2014 ${notReadReason(status, engine)}`),
|
|
12119
|
-
...(n.notRead?.length ?? 0) > NOT_READ_SHOWN ? [` and ${(n.notRead?.length ?? 0) - NOT_READ_SHOWN} more not read \u2014 --json lists them all`] : []
|
|
12307
|
+
...(n.notRead ?? []).slice(0, NOT_READ_SHOWN).map(({ path, status, engine, reason }) => ` not read: ${path} \u2014 ${reason !== void 0 && reason === n.ocr?.unavailable ? "waits for OCR, below" : notReadReason(status, engine, reason)}`),
|
|
12308
|
+
...(n.notRead?.length ?? 0) > NOT_READ_SHOWN ? [` and ${(n.notRead?.length ?? 0) - NOT_READ_SHOWN} more not read \u2014 --json lists them all`] : [],
|
|
12309
|
+
...n.ocr === void 0 ? [] : [
|
|
12310
|
+
` OCR${run2.scans?.engine ? ` (${run2.scans.engine})` : ""}: ${n.ocr.read} read, ${n.ocr.notRead} not read` + (n.ocr.picturesWaiting ? `, ${n.ocr.picturesWaiting} pictures waiting` : "") + (n.ocr.unavailable ? ` \u2014 ${n.ocr.unavailable}` : "")
|
|
12311
|
+
]
|
|
12120
12312
|
]),
|
|
12313
|
+
...run2.scans?.warning ? [`warning: ${run2.scans.warning}`] : [],
|
|
12121
12314
|
...run2.notesEmbedded === void 0 ? [] : [
|
|
12122
12315
|
`notes by meaning: ${run2.notesEmbedded.chunks} chunks embedded` + (run2.notesEmbedded.notEmbedded !== void 0 ? ` \u2014 ${run2.notesEmbedded.notEmbedded}` : run2.notesEmbedded.left ? " \u2014 more next run" : "")
|
|
12123
12316
|
],
|
|
@@ -12133,7 +12326,7 @@ var failureReason = /* @__PURE__ */ __name((error, failure, debug) => {
|
|
|
12133
12326
|
}, "failureReason");
|
|
12134
12327
|
var syncCommand = /* @__PURE__ */ __name((program, streams, env, keyring) => {
|
|
12135
12328
|
const { print } = answers(program, streams, env);
|
|
12136
|
-
notLocalPaths2(
|
|
12329
|
+
notLocalPaths2(annotate8(program.command("sync"), { effects: FETCH3 }), "folder", "ignore").summary("bring the notes folders up to date in the store and searchable by meaning").description("bring every configured notes folder up to date in the store, only what changed, and embed the new chunks for search by meaning. Every configured folder unless narrowed; --timeout keeps the progress made so far").addOption(new Option("--folder <folder>", "only this configured folder, by its id or path; repeat for more").argParser(collect)).addOption(new Option("--ignore <path>", "leave this file or folder alone this run, a path or a glob; repeat for more").argParser(collect)).option("--no-embed", "skip embedding notes for search by meaning this run").action(async (options, command) => {
|
|
12137
12330
|
const stop = environmentOf5(command).signal;
|
|
12138
12331
|
const halt = /* @__PURE__ */ __name(() => {
|
|
12139
12332
|
if (stop?.aborted)
|
|
@@ -12175,10 +12368,24 @@ var syncCommand = /* @__PURE__ */ __name((program, streams, env, keyring) => {
|
|
|
12175
12368
|
const ignore = config.notes?.ignore ?? [];
|
|
12176
12369
|
const skip = options.ignore ?? [];
|
|
12177
12370
|
const json = command.optsWithGlobals().json !== void 0;
|
|
12371
|
+
const choice = readScans(command);
|
|
12372
|
+
const scans = folders.length > 0 ? await scanReader(choice, {
|
|
12373
|
+
app: APP,
|
|
12374
|
+
env,
|
|
12375
|
+
command: APP.command,
|
|
12376
|
+
...keyring ? { keyring } : {},
|
|
12377
|
+
...stop ? { signal: stop } : {}
|
|
12378
|
+
}) : void 0;
|
|
12379
|
+
if (scans)
|
|
12380
|
+
run2.scans = {
|
|
12381
|
+
readScans: choice,
|
|
12382
|
+
engine: scans.extractor ?? null,
|
|
12383
|
+
...scans.warning ? { warning: scans.warning } : {}
|
|
12384
|
+
};
|
|
12178
12385
|
for (const folder of folders)
|
|
12179
12386
|
await attempt(`notes ${folder.path}`, async () => {
|
|
12180
12387
|
const onFile = progressLine(streams.diagnostic, json, { step: "notes", unit: "files", label: folder.id });
|
|
12181
|
-
run2.notes.push(await importNotes(store, folder, { ignore, skip, env, onFile }));
|
|
12388
|
+
run2.notes.push(await importNotes(store, folder, { ignore, skip, env, onFile, ...scans ? { scans } : {} }));
|
|
12182
12389
|
});
|
|
12183
12390
|
if (folders.length > 0)
|
|
12184
12391
|
await attempt("notes by meaning", async () => {
|
|
@@ -12212,7 +12419,7 @@ var update = appUpdate({
|
|
|
12212
12419
|
command: IDENTITY.command,
|
|
12213
12420
|
version: IDENTITY.version,
|
|
12214
12421
|
entry: new URL("../program.js", import.meta.url).href,
|
|
12215
|
-
statePath: /* @__PURE__ */ __name((env) =>
|
|
12422
|
+
statePath: /* @__PURE__ */ __name((env) => join14(resolvePaths6({ appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env }).state, "update-check.json"), "statePath"),
|
|
12216
12423
|
// biome-ignore lint/plugin/no-own-settings: the update check runs before any command exists to give baseContext
|
|
12217
12424
|
enabled: /* @__PURE__ */ __name((env) => configuration.resolveSettings({}, { env, needsProfile: false }).updateCheck, "enabled"),
|
|
12218
12425
|
offVariables: [`${IDENTITY.envPrefix}_NO_UPDATE_CHECK`]
|
|
@@ -12229,6 +12436,7 @@ var fileCommands = /* @__PURE__ */ __name((options) => {
|
|
|
12229
12436
|
const keyring = options.keyring;
|
|
12230
12437
|
const root = new Command(IDENTITY.command);
|
|
12231
12438
|
notesCommand(root, streams, env);
|
|
12439
|
+
noteLinksCommand(root, streams, env);
|
|
12232
12440
|
foldersCommand(root, streams, env);
|
|
12233
12441
|
sourcesCommand(root, streams, env, {
|
|
12234
12442
|
...options.fetchPage ? { fetch: options.fetchPage } : {},
|
|
@@ -12263,7 +12471,7 @@ var definition = /* @__PURE__ */ __name((options = {}) => ({
|
|
|
12263
12471
|
commands: /* @__PURE__ */ __name(() => [
|
|
12264
12472
|
...fileCommands(options),
|
|
12265
12473
|
commandsCommand(IDENTITY),
|
|
12266
|
-
appDoctorCommand(IDENTITY, configuration, { packageName: PACKAGE }),
|
|
12474
|
+
appDoctorCommand(IDENTITY, configuration, { packageName: PACKAGE, local: notesFolderCheck }),
|
|
12267
12475
|
skillCommand(IDENTITY, SKILL),
|
|
12268
12476
|
mcpCommand(),
|
|
12269
12477
|
upgradeCommand(IDENTITY, PACKAGE, (command) => ({
|