@gadicc/loom 2.3.1 → 2.5.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/.loom-source-manifest.json +10 -1
- package/esm/src/cli/machineSlots.d.ts +149 -0
- package/esm/src/cli/machineSlots.d.ts.map +1 -0
- package/esm/src/cli/machineSlots.js +417 -0
- package/esm/src/cli/machineSlots.js.map +1 -0
- package/esm/src/cli/machineSlotsCommand.d.ts +24 -0
- package/esm/src/cli/machineSlotsCommand.d.ts.map +1 -0
- package/esm/src/cli/machineSlotsCommand.js +431 -0
- package/esm/src/cli/machineSlotsCommand.js.map +1 -0
- package/esm/src/cli/machineSlotsHost.d.ts +50 -0
- package/esm/src/cli/machineSlotsHost.d.ts.map +1 -0
- package/esm/src/cli/machineSlotsHost.js +192 -0
- package/esm/src/cli/machineSlotsHost.js.map +1 -0
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +39 -1
- package/esm/src/cli/mod.js.map +1 -1
- package/esm/src/cli/testResourceLaunch.d.ts +29 -1
- package/esm/src/cli/testResourceLaunch.d.ts.map +1 -1
- package/esm/src/cli/testResourceLaunch.js +49 -12
- package/esm/src/cli/testResourceLaunch.js.map +1 -1
- package/esm/src/geo/client.d.ts +74 -0
- package/esm/src/geo/client.d.ts.map +1 -0
- package/esm/src/geo/client.js +135 -0
- package/esm/src/geo/client.js.map +1 -0
- package/esm/src/geo/mod.d.ts +5 -0
- package/esm/src/geo/mod.d.ts.map +1 -0
- package/esm/src/geo/mod.js +5 -0
- package/esm/src/geo/mod.js.map +1 -0
- package/esm/src/geo/place.d.ts +28 -0
- package/esm/src/geo/place.d.ts.map +1 -0
- package/esm/src/geo/place.js +41 -0
- package/esm/src/geo/place.js.map +1 -0
- package/esm/src/geo/places.d.ts +16 -0
- package/esm/src/geo/places.d.ts.map +1 -0
- package/esm/src/geo/places.js +154 -0
- package/esm/src/geo/places.js.map +1 -0
- package/esm/src/geo/placesFormat.d.ts +49 -0
- package/esm/src/geo/placesFormat.d.ts.map +1 -0
- package/esm/src/geo/placesFormat.js +38 -0
- package/esm/src/geo/placesFormat.js.map +1 -0
- package/esm/src/geo/preference.d.ts +15 -0
- package/esm/src/geo/preference.d.ts.map +1 -0
- package/esm/src/geo/preference.js +21 -0
- package/esm/src/geo/preference.js.map +1 -0
- package/esm/src/geo/timeZone.d.ts +20 -0
- package/esm/src/geo/timeZone.d.ts.map +1 -0
- package/esm/src/geo/timeZone.js +65 -0
- package/esm/src/geo/timeZone.js.map +1 -0
- package/esm/src/geo/vercel.d.ts +15 -0
- package/esm/src/geo/vercel.d.ts.map +1 -0
- package/esm/src/geo/vercel.js +64 -0
- package/esm/src/geo/vercel.js.map +1 -0
- package/package.json +26 -2
- package/skills/loom/SKILL.md +43 -15
- package/skills/loom/references/verification-workflow.md +128 -0
- package/source/src/cli/machineSlots.ts +543 -0
- package/source/src/cli/machineSlotsCommand.ts +549 -0
- package/source/src/cli/machineSlotsHost.ts +215 -0
- package/source/src/cli/mod.ts +53 -1
- package/source/src/cli/testResourceLaunch.ts +71 -9
- package/source/src/geo/client.ts +241 -0
- package/source/src/geo/mod.ts +12 -0
- package/source/src/geo/place.ts +61 -0
- package/source/src/geo/places.ts +195 -0
- package/source/src/geo/placesFormat.ts +58 -0
- package/source/src/geo/preference.ts +24 -0
- package/source/src/geo/timeZone.ts +78 -0
- package/source/src/geo/vercel.ts +78 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { foldPlaceName, PLACES_FORMAT, } from "./placesFormat.js";
|
|
2
|
+
export { foldPlaceName, PLACES_FORMAT, } from "./placesFormat.js";
|
|
3
|
+
/**
|
|
4
|
+
* Common names for a country that are neither its ISO code nor a prefix of
|
|
5
|
+
* its English name, so "london, uk" and "paris, usa" narrow as people type
|
|
6
|
+
* them.
|
|
7
|
+
*/
|
|
8
|
+
const COUNTRY_ALIASES = {
|
|
9
|
+
uk: "GB",
|
|
10
|
+
usa: "US",
|
|
11
|
+
uae: "AE",
|
|
12
|
+
};
|
|
13
|
+
/** Longer queries are cut; no place name needs more. */
|
|
14
|
+
export const MAX_QUERY_LENGTH = 64;
|
|
15
|
+
const MAX_LIMIT = 50;
|
|
16
|
+
/** Ranks, best first; a row takes the best that applies. */
|
|
17
|
+
const EXACT = 0;
|
|
18
|
+
const PREFIX = 1; // also an exact alternate name ("munchen" → Munich)
|
|
19
|
+
const WORD_PREFIX = 2; // "york" in "new york"
|
|
20
|
+
const ALTERNATE_PREFIX = 3;
|
|
21
|
+
const DISTRICT = 4; // any match on a city's district ("Zürich (Kreis 11)")
|
|
22
|
+
function regionsOf(header) {
|
|
23
|
+
const names = new Intl.DisplayNames(["en"], { type: "region" });
|
|
24
|
+
const countryNames = new Map();
|
|
25
|
+
return header.regions.map(([country, name, code = ""]) => {
|
|
26
|
+
let countryName = countryNames.get(country);
|
|
27
|
+
if (countryName === undefined) {
|
|
28
|
+
try {
|
|
29
|
+
countryName = foldPlaceName(names.of(country) ?? country);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
countryName = country.toLowerCase();
|
|
33
|
+
}
|
|
34
|
+
countryNames.set(country, countryName);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
country,
|
|
38
|
+
name,
|
|
39
|
+
folded: foldPlaceName(name),
|
|
40
|
+
countryName,
|
|
41
|
+
code: code.toLowerCase(),
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parses a places file (format in `placesFormat.ts`). Throws on a header
|
|
47
|
+
* it doesn't know or a row count that doesn't match, rather than serving
|
|
48
|
+
* a half-read list.
|
|
49
|
+
*/
|
|
50
|
+
export function createPlaceIndex(text) {
|
|
51
|
+
const end = text.indexOf("\n");
|
|
52
|
+
const header = JSON.parse(text.slice(0, end));
|
|
53
|
+
if (header.format !== PLACES_FORMAT ||
|
|
54
|
+
!Array.isArray(header.timezones) ||
|
|
55
|
+
!Array.isArray(header.regions)) {
|
|
56
|
+
throw new Error("places: unknown file format");
|
|
57
|
+
}
|
|
58
|
+
const regions = regionsOf(header);
|
|
59
|
+
const rows = [];
|
|
60
|
+
for (const line of text.slice(end + 1).split("\n")) {
|
|
61
|
+
if (!line)
|
|
62
|
+
continue;
|
|
63
|
+
const [name, ascii, region, latitude, longitude, timezone, district, alts] = line.split("\t");
|
|
64
|
+
const r = regions[Number(region)];
|
|
65
|
+
const tz = header.timezones[Number(timezone)];
|
|
66
|
+
const lat = Number(latitude);
|
|
67
|
+
const lon = Number(longitude);
|
|
68
|
+
if (!name || !r || !tz || !Number.isFinite(lat) || !Number.isFinite(lon)) {
|
|
69
|
+
throw new Error(`places: bad row ${rows.length + 1}`);
|
|
70
|
+
}
|
|
71
|
+
const place = {
|
|
72
|
+
name,
|
|
73
|
+
...(r.name ? { region: r.name } : {}),
|
|
74
|
+
country: r.country,
|
|
75
|
+
latitude: lat,
|
|
76
|
+
longitude: lon,
|
|
77
|
+
timezone: tz,
|
|
78
|
+
};
|
|
79
|
+
const folded = foldPlaceName(name);
|
|
80
|
+
const foldedAscii = ascii ? foldPlaceName(ascii) : folded;
|
|
81
|
+
rows.push({
|
|
82
|
+
place,
|
|
83
|
+
region: Number(region),
|
|
84
|
+
keys: foldedAscii === folded ? [folded] : [folded, foldedAscii],
|
|
85
|
+
alternates: alts ? alts.split("|") : [],
|
|
86
|
+
district: district === "1",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (rows.length !== header.rows) {
|
|
90
|
+
throw new Error(`places: ${rows.length} rows, header says ${header.rows}`);
|
|
91
|
+
}
|
|
92
|
+
/** Which regions every "where" term after the first comma allows. */
|
|
93
|
+
function allowedRegions(wheres) {
|
|
94
|
+
if (!wheres.length)
|
|
95
|
+
return null;
|
|
96
|
+
return regions.map((r) => wheres.every((w) => r.country.toLowerCase() === w ||
|
|
97
|
+
COUNTRY_ALIASES[w] === r.country ||
|
|
98
|
+
// Exactly: "n" or "ni" is not Northern Ireland ("NIR").
|
|
99
|
+
(r.code !== "" && r.code === w) ||
|
|
100
|
+
r.countryName.startsWith(w) ||
|
|
101
|
+
r.folded.startsWith(w)));
|
|
102
|
+
}
|
|
103
|
+
function rank(row, q) {
|
|
104
|
+
if (row.keys.includes(q))
|
|
105
|
+
return EXACT;
|
|
106
|
+
if (row.keys.some((k) => k.startsWith(q)) || row.alternates.includes(q)) {
|
|
107
|
+
return PREFIX;
|
|
108
|
+
}
|
|
109
|
+
if (row.keys.some((k) => k.includes(` ${q}`) || k.includes(`-${q}`))) {
|
|
110
|
+
return WORD_PREFIX;
|
|
111
|
+
}
|
|
112
|
+
if (row.alternates.some((a) => a.startsWith(q)))
|
|
113
|
+
return ALTERNATE_PREFIX;
|
|
114
|
+
return -1;
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
size: rows.length,
|
|
118
|
+
search(q, limit = 8) {
|
|
119
|
+
const text = q.trim().slice(0, MAX_QUERY_LENGTH);
|
|
120
|
+
if (text.length < 2)
|
|
121
|
+
return [];
|
|
122
|
+
const [first, ...rest] = text.split(",");
|
|
123
|
+
const name = foldPlaceName(first);
|
|
124
|
+
if (name.length < 2)
|
|
125
|
+
return [];
|
|
126
|
+
const allowed = allowedRegions(rest.map(foldPlaceName).filter((w) => w !== ""));
|
|
127
|
+
const max = Number.isFinite(limit)
|
|
128
|
+
? Math.min(Math.max(Math.floor(limit), 1), MAX_LIMIT)
|
|
129
|
+
: 8;
|
|
130
|
+
// Rows are in population order, so each tier fills biggest first.
|
|
131
|
+
const tiers = [[], [], [], [], []];
|
|
132
|
+
for (const row of rows) {
|
|
133
|
+
if (allowed && !allowed[row.region])
|
|
134
|
+
continue;
|
|
135
|
+
let tier = rank(row, name);
|
|
136
|
+
if (tier < 0)
|
|
137
|
+
continue;
|
|
138
|
+
if (row.district)
|
|
139
|
+
tier = DISTRICT;
|
|
140
|
+
if (tiers[tier].length < max)
|
|
141
|
+
tiers[tier].push(row.place);
|
|
142
|
+
// Nothing found later can outrank a full first tier.
|
|
143
|
+
if (tiers[EXACT].length >= max)
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
// Copies, so a caller can't change the index.
|
|
147
|
+
return tiers
|
|
148
|
+
.flat()
|
|
149
|
+
.slice(0, max)
|
|
150
|
+
.map((place) => ({ ...place }));
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=places.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"places.js","sourceRoot":"","sources":["../../../source/src/geo/places.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,GAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,aAAa,EACb,aAAa,GAEd,MAAM,mBAAmB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,eAAe,GAA2B;IAC9C,EAAE,EAAE,IAAI;IACR,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;CACV,CAAC;AAEF,wDAAwD;AACxD,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AACnC,MAAM,SAAS,GAAG,EAAE,CAAC;AA4BrB,4DAA4D;AAC5D,MAAM,KAAK,GAAG,CAAC,CAAC;AAChB,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,oDAAoD;AACtE,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC,uBAAuB;AAC9C,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,uDAAuD;AAE3E,SAAS,SAAS,CAAC,MAAoB;IACrC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChE,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC/C,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAA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
|
+
/**
|
|
2
|
+
* The format of `places.tsv`, shared by the script that writes it
|
|
3
|
+
* (`scripts/geonames/build.ts`) and the search that reads it
|
|
4
|
+
* (`places.ts`). Pure and free of `server-only` so the build script can
|
|
5
|
+
* import it; nothing here holds the data itself.
|
|
6
|
+
*
|
|
7
|
+
* The file is one JSON header line, then one tab-separated line per place
|
|
8
|
+
* in descending population order (the order is the ranking, so there is
|
|
9
|
+
* no population column):
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* {"format":2,...,"rows":N,"timezones":[...],"regions":[["GB","England","ENG"],["UA","Kyiv City"],...]}
|
|
13
|
+
* name ascii region latitude longitude timezone district alternates
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* - `ascii`: GeoNames' ASCII name, empty when it equals `name`.
|
|
17
|
+
* - `region`, `timezone`: indexes into the header's lists.
|
|
18
|
+
* - `latitude`, `longitude`: degrees rounded to 3 decimals (~100 m).
|
|
19
|
+
* - `district`: `1` for a section of a city (GeoNames `PPLX`), else empty.
|
|
20
|
+
* - `alternates`: `|`-separated, already folded (`foldPlaceName`).
|
|
21
|
+
*/
|
|
22
|
+
/** Bumped whenever a column or the header changes meaning. */
|
|
23
|
+
export declare const PLACES_FORMAT = 2;
|
|
24
|
+
/** The JSON header on the file's first line. */
|
|
25
|
+
export interface PlacesHeader {
|
|
26
|
+
format: typeof PLACES_FORMAT;
|
|
27
|
+
/** Which GeoNames files, from when. */
|
|
28
|
+
source: string;
|
|
29
|
+
/** Licence and a pointer to what was changed. */
|
|
30
|
+
license: string;
|
|
31
|
+
/** Number of place lines that follow. */
|
|
32
|
+
rows: number;
|
|
33
|
+
/** IANA time zones, indexed by the timezone column. */
|
|
34
|
+
timezones: string[];
|
|
35
|
+
/**
|
|
36
|
+
* `[country code, first-level region name or ""]`, indexed by the region
|
|
37
|
+
* column, with the region's code third when it is letters (GeoNames'
|
|
38
|
+
* admin1 code: "TX", "DC", "ENG"; not Canada's "08").
|
|
39
|
+
*/
|
|
40
|
+
regions: ([string, string] | [string, string, string])[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Lower case, without accents or repeated spaces, so "São Paulo", "sao
|
|
44
|
+
* paulo" and "SAO PAULO" compare equal. The build folds the alternates
|
|
45
|
+
* with this and the search folds names and queries with it, so the two
|
|
46
|
+
* must stay one function.
|
|
47
|
+
*/
|
|
48
|
+
export declare function foldPlaceName(text: string): string;
|
|
49
|
+
//# sourceMappingURL=placesFormat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placesFormat.d.ts","sourceRoot":"","sources":["../../../source/src/geo/placesFormat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,8DAA8D;AAC9D,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,gDAAgD;AAChD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,OAAO,aAAa,CAAC;IAC7B,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB;;;;OAIG;IACH,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;CAC1D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOlD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The format of `places.tsv`, shared by the script that writes it
|
|
3
|
+
* (`scripts/geonames/build.ts`) and the search that reads it
|
|
4
|
+
* (`places.ts`). Pure and free of `server-only` so the build script can
|
|
5
|
+
* import it; nothing here holds the data itself.
|
|
6
|
+
*
|
|
7
|
+
* The file is one JSON header line, then one tab-separated line per place
|
|
8
|
+
* in descending population order (the order is the ranking, so there is
|
|
9
|
+
* no population column):
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* {"format":2,...,"rows":N,"timezones":[...],"regions":[["GB","England","ENG"],["UA","Kyiv City"],...]}
|
|
13
|
+
* name ascii region latitude longitude timezone district alternates
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* - `ascii`: GeoNames' ASCII name, empty when it equals `name`.
|
|
17
|
+
* - `region`, `timezone`: indexes into the header's lists.
|
|
18
|
+
* - `latitude`, `longitude`: degrees rounded to 3 decimals (~100 m).
|
|
19
|
+
* - `district`: `1` for a section of a city (GeoNames `PPLX`), else empty.
|
|
20
|
+
* - `alternates`: `|`-separated, already folded (`foldPlaceName`).
|
|
21
|
+
*/
|
|
22
|
+
/** Bumped whenever a column or the header changes meaning. */
|
|
23
|
+
export const PLACES_FORMAT = 2;
|
|
24
|
+
/**
|
|
25
|
+
* Lower case, without accents or repeated spaces, so "São Paulo", "sao
|
|
26
|
+
* paulo" and "SAO PAULO" compare equal. The build folds the alternates
|
|
27
|
+
* with this and the search folds names and queries with it, so the two
|
|
28
|
+
* must stay one function.
|
|
29
|
+
*/
|
|
30
|
+
export function foldPlaceName(text) {
|
|
31
|
+
return text
|
|
32
|
+
.normalize("NFD")
|
|
33
|
+
.replace(/\p{M}/gu, "")
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.replace(/\s+/g, " ")
|
|
36
|
+
.trim();
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=placesFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placesFormat.js","sourceRoot":"","sources":["../../../source/src/geo/placesFormat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAqB/B;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,IAAI;SACR,SAAS,CAAC,KAAK,CAAC;SAChB,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;SACtB,WAAW,EAAE;SACb,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Place } from "./place.js";
|
|
2
|
+
/** A future default, distinct from an acquired position or an entry override. */
|
|
3
|
+
export type LocationPreference = {
|
|
4
|
+
version: 2;
|
|
5
|
+
mode: "automatic";
|
|
6
|
+
} | {
|
|
7
|
+
version: 2;
|
|
8
|
+
mode: "fixed";
|
|
9
|
+
place: Place;
|
|
10
|
+
};
|
|
11
|
+
/** The default stores no detected or device coordinates. */
|
|
12
|
+
export declare const AUTOMATIC_LOCATION: LocationPreference;
|
|
13
|
+
/** Validates versioned browser JSON, preserving only explicit fixed-city intent. */
|
|
14
|
+
export declare function toLocationPreference(value: unknown): LocationPreference | null;
|
|
15
|
+
//# sourceMappingURL=preference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preference.d.ts","sourceRoot":"","sources":["../../../source/src/geo/preference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAW,MAAM,YAAY,CAAC;AAEjD,iFAAiF;AACjF,MAAM,MAAM,kBAAkB,GAC1B;IAAE,OAAO,EAAE,CAAC,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GACjC;IAAE,OAAO,EAAE,CAAC,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAChD,4DAA4D;AAC5D,eAAO,MAAM,kBAAkB,EAAE,kBAG/B,CAAC;AAEH,oFAAoF;AACpF,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,kBAAkB,GAAG,IAAI,CAQ3B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { toPlace } from "./place.js";
|
|
2
|
+
/** The default stores no detected or device coordinates. */
|
|
3
|
+
export const AUTOMATIC_LOCATION = Object.freeze({
|
|
4
|
+
version: 2,
|
|
5
|
+
mode: "automatic",
|
|
6
|
+
});
|
|
7
|
+
/** Validates versioned browser JSON, preserving only explicit fixed-city intent. */
|
|
8
|
+
export function toLocationPreference(value) {
|
|
9
|
+
if (typeof value !== "object" || value === null)
|
|
10
|
+
return null;
|
|
11
|
+
const v = value;
|
|
12
|
+
if (v.version !== 2)
|
|
13
|
+
return null;
|
|
14
|
+
if (v.mode === "automatic")
|
|
15
|
+
return AUTOMATIC_LOCATION;
|
|
16
|
+
if (v.mode !== "fixed")
|
|
17
|
+
return null;
|
|
18
|
+
const place = toPlace(v.place);
|
|
19
|
+
return place ? { version: 2, mode: "fixed", place } : null;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=preference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preference.js","sourceRoot":"","sources":["../../../source/src/geo/preference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,EAAE,MAAM,YAAY,CAAC;AAMjD,4DAA4D;AAC5D,MAAM,CAAC,MAAM,kBAAkB,GAAuB,MAAM,CAAC,MAAM,CAAC;IAClE,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,WAAW;CAClB,CAAC,CAAC;AAEH,oFAAoF;AACpF,MAAM,UAAU,oBAAoB,CAClC,KAAc;IAEd,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC7D,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACjC,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,kBAAkB,CAAC;IACtD,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The zone's offset from UTC at `date`, in minutes east (London in summer
|
|
3
|
+
* 60, New York in winter -300). Throws a RangeError for a zone the runtime
|
|
4
|
+
* does not know.
|
|
5
|
+
*/
|
|
6
|
+
export declare function utcOffsetMinutes(zone: string, date: Date): number;
|
|
7
|
+
/**
|
|
8
|
+
* The device's IANA time zone, or undefined where the runtime has none or
|
|
9
|
+
* names one it can't then use.
|
|
10
|
+
*/
|
|
11
|
+
export declare function deviceTimeZone(): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Whether a clock in `zone` would read differently from one in `deviceZone`
|
|
14
|
+
* at any of `times`. Compares UTC offsets, not names, since sources name the
|
|
15
|
+
* same zone differently (GeoNames' Asia/Kolkata is V8's Asia/Calcutta, and
|
|
16
|
+
* Europe/Kyiv is Europe/Kiev in older data). False when either zone is
|
|
17
|
+
* unknown to the runtime: no note is better than a wrong one.
|
|
18
|
+
*/
|
|
19
|
+
export declare function clocksDiffer(zone: string, deviceZone: string, times: readonly Date[]): boolean;
|
|
20
|
+
//# sourceMappingURL=timeZone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeZone.d.ts","sourceRoot":"","sources":["../../../source/src/geo/timeZone.ts"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAejE;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,MAAM,GAAG,SAAS,CASnD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,SAAS,IAAI,EAAE,GACrB,OAAO,CAST"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const formatters = new Map();
|
|
2
|
+
function formatterFor(zone) {
|
|
3
|
+
let formatter = formatters.get(zone);
|
|
4
|
+
if (!formatter) {
|
|
5
|
+
formatter = new Intl.DateTimeFormat("en-US", {
|
|
6
|
+
timeZone: zone,
|
|
7
|
+
hourCycle: "h23",
|
|
8
|
+
year: "numeric",
|
|
9
|
+
month: "numeric",
|
|
10
|
+
day: "numeric",
|
|
11
|
+
hour: "numeric",
|
|
12
|
+
minute: "numeric",
|
|
13
|
+
second: "numeric",
|
|
14
|
+
});
|
|
15
|
+
formatters.set(zone, formatter);
|
|
16
|
+
}
|
|
17
|
+
return formatter;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The zone's offset from UTC at `date`, in minutes east (London in summer
|
|
21
|
+
* 60, New York in winter -300). Throws a RangeError for a zone the runtime
|
|
22
|
+
* does not know.
|
|
23
|
+
*/
|
|
24
|
+
export function utcOffsetMinutes(zone, date) {
|
|
25
|
+
const parts = {};
|
|
26
|
+
for (const part of formatterFor(zone).formatToParts(date)) {
|
|
27
|
+
if (part.type !== "literal")
|
|
28
|
+
parts[part.type] = Number(part.value);
|
|
29
|
+
}
|
|
30
|
+
const wall = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second);
|
|
31
|
+
const instant = Math.floor(date.getTime() / 1000) * 1000;
|
|
32
|
+
return Math.round((wall - instant) / 60_000);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The device's IANA time zone, or undefined where the runtime has none or
|
|
36
|
+
* names one it can't then use.
|
|
37
|
+
*/
|
|
38
|
+
export function deviceTimeZone() {
|
|
39
|
+
try {
|
|
40
|
+
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
41
|
+
if (!zone)
|
|
42
|
+
return undefined;
|
|
43
|
+
formatterFor(zone);
|
|
44
|
+
return zone;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Whether a clock in `zone` would read differently from one in `deviceZone`
|
|
52
|
+
* at any of `times`. Compares UTC offsets, not names, since sources name the
|
|
53
|
+
* same zone differently (GeoNames' Asia/Kolkata is V8's Asia/Calcutta, and
|
|
54
|
+
* Europe/Kyiv is Europe/Kiev in older data). False when either zone is
|
|
55
|
+
* unknown to the runtime: no note is better than a wrong one.
|
|
56
|
+
*/
|
|
57
|
+
export function clocksDiffer(zone, deviceZone, times) {
|
|
58
|
+
try {
|
|
59
|
+
return times.some((time) => utcOffsetMinutes(zone, time) !== utcOffsetMinutes(deviceZone, time));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=timeZone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeZone.js","sourceRoot":"","sources":["../../../source/src/geo/timeZone.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,IAAI,GAAG,EAA+B,CAAC;AAE1D,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,SAAS,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;YAC3C,QAAQ,EAAE,IAAI;YACd,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,SAAS;YACd,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE,SAAS;SAClB,CAAC,CAAC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1B,IAAY,EACZ,UAAkB,EAClB,KAAsB;IAEtB,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,IAAI,CACf,CAAC,IAAI,EAAE,EAAE,CACP,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,CACtE,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Place } from "./place.js";
|
|
2
|
+
/** `@vercel/functions` has no constant for this one. */
|
|
3
|
+
export declare const TIMEZONE_HEADER_NAME = "x-vercel-ip-timezone";
|
|
4
|
+
/** A request-header reader, including Next's read-only headers. */
|
|
5
|
+
export interface HeaderReader {
|
|
6
|
+
get(name: string): string | null;
|
|
7
|
+
}
|
|
8
|
+
/** A usable IP place and decoded city label, which is not an accuracy guarantee. */
|
|
9
|
+
export interface DetectedPlace {
|
|
10
|
+
place: Place;
|
|
11
|
+
cityName?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Parses Vercel hints without throwing on missing coordinates or encoded cities. */
|
|
14
|
+
export declare function parseVercelLocation(headers: HeaderReader, unnamed?: string): DetectedPlace | null;
|
|
15
|
+
//# sourceMappingURL=vercel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercel.d.ts","sourceRoot":"","sources":["../../../source/src/geo/vercel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAW,MAAM,YAAY,CAAC;AAEjD,wDAAwD;AACxD,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AA2C3D,mEAAmE;AACnE,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qFAAqF;AACrF,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,YAAY,EACrB,OAAO,SAAc,GACpB,aAAa,GAAG,IAAI,CAgBtB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { toPlace } from "./place.js";
|
|
2
|
+
/** `@vercel/functions` has no constant for this one. */
|
|
3
|
+
export const TIMEZONE_HEADER_NAME = "x-vercel-ip-timezone";
|
|
4
|
+
/** A plain decimal, as Vercel sends: no exponent, hex or empty string. */
|
|
5
|
+
const DECIMAL = /^-?\d+(?:\.\d+)?$/;
|
|
6
|
+
function coordinate(headers, name) {
|
|
7
|
+
const value = headers.get(name)?.trim();
|
|
8
|
+
return value && DECIMAL.test(value) ? Number(value) : undefined;
|
|
9
|
+
}
|
|
10
|
+
/** The city, decoded from RFC 3986, or undefined when it doesn't decode. */
|
|
11
|
+
function city(headers) {
|
|
12
|
+
const raw = headers.get("x-vercel-ip-city");
|
|
13
|
+
if (!raw)
|
|
14
|
+
return undefined;
|
|
15
|
+
try {
|
|
16
|
+
return decodeURIComponent(raw).trim() || undefined;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** The country's English name ("United Kingdom"), when Intl knows it. */
|
|
23
|
+
function countryName(country) {
|
|
24
|
+
try {
|
|
25
|
+
const name = new Intl.DisplayNames(["en"], { type: "region" }).of(country);
|
|
26
|
+
return name && name !== country ? name : undefined;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** The zone when this runtime knows it as an IANA name, else undefined. */
|
|
33
|
+
function timezone(headers) {
|
|
34
|
+
const value = headers.get(TIMEZONE_HEADER_NAME)?.trim();
|
|
35
|
+
if (!value)
|
|
36
|
+
return undefined;
|
|
37
|
+
try {
|
|
38
|
+
new Intl.DateTimeFormat("en", { timeZone: value });
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Parses Vercel hints without throwing on missing coordinates or encoded cities. */
|
|
46
|
+
export function parseVercelLocation(headers, unnamed = "Your area") {
|
|
47
|
+
const latitude = coordinate(headers, "x-vercel-ip-latitude");
|
|
48
|
+
const longitude = coordinate(headers, "x-vercel-ip-longitude");
|
|
49
|
+
if (latitude === undefined || longitude === undefined)
|
|
50
|
+
return null;
|
|
51
|
+
const code = headers.get("x-vercel-ip-country")?.trim().toUpperCase();
|
|
52
|
+
const country = code && /^[A-Z]{2}$/.test(code) ? code : undefined;
|
|
53
|
+
const decoded = city(headers);
|
|
54
|
+
const cityName = decoded && decoded.length <= 200 ? decoded : undefined;
|
|
55
|
+
const place = toPlace({
|
|
56
|
+
name: cityName ?? (country ? countryName(country) : undefined) ?? unnamed,
|
|
57
|
+
country,
|
|
58
|
+
latitude,
|
|
59
|
+
longitude,
|
|
60
|
+
timezone: timezone(headers),
|
|
61
|
+
});
|
|
62
|
+
return place ? { place, ...(cityName ? { cityName } : {}) } : null;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=vercel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercel.js","sourceRoot":"","sources":["../../../source/src/geo/vercel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,EAAE,MAAM,YAAY,CAAC;AAEjD,wDAAwD;AACxD,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAE3D,0EAA0E;AAC1E,MAAM,OAAO,GAAG,mBAAmB,CAAC;AAEpC,SAAS,UAAU,CAAC,OAAqB,EAAE,IAAY;IACrD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;IACxC,OAAO,KAAK,IAAI,OAAO,CAAC,IAAI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"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Shared helpers and verification tooling for Next.js applications.",
|
|
5
5
|
"homepage": "https://github.com/gadicc/loom#readme",
|
|
6
6
|
"repository": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://github.com/gadicc/loom/issues"
|
|
12
12
|
},
|
|
13
13
|
"loom": {
|
|
14
|
-
"gitCommit": "
|
|
14
|
+
"gitCommit": "210d717b1e3b24e4cf8002382fda32f728b25372"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
|
17
17
|
"main": "./esm/mod.js",
|
|
@@ -41,6 +41,18 @@
|
|
|
41
41
|
"types": "./esm/src/files/mod.d.ts",
|
|
42
42
|
"import": "./esm/src/files/mod.js"
|
|
43
43
|
},
|
|
44
|
+
"./src/geo/mod.js": {
|
|
45
|
+
"types": "./esm/src/geo/mod.d.ts",
|
|
46
|
+
"import": "./esm/src/geo/mod.js"
|
|
47
|
+
},
|
|
48
|
+
"./src/geo/client.js": {
|
|
49
|
+
"types": "./esm/src/geo/client.d.ts",
|
|
50
|
+
"import": "./esm/src/geo/client.js"
|
|
51
|
+
},
|
|
52
|
+
"./src/geo/places.js": {
|
|
53
|
+
"types": "./esm/src/geo/places.d.ts",
|
|
54
|
+
"import": "./esm/src/geo/places.js"
|
|
55
|
+
},
|
|
44
56
|
"./src/mail/mod.js": {
|
|
45
57
|
"types": "./esm/src/mail/mod.d.ts",
|
|
46
58
|
"import": "./esm/src/mail/mod.js"
|
|
@@ -157,6 +169,18 @@
|
|
|
157
169
|
"import": "./db/valibot.js",
|
|
158
170
|
"default": "./db/valibot.js"
|
|
159
171
|
},
|
|
172
|
+
"./geo": {
|
|
173
|
+
"types": "./esm/src/geo/mod.d.ts",
|
|
174
|
+
"import": "./esm/src/geo/mod.js"
|
|
175
|
+
},
|
|
176
|
+
"./geo/client": {
|
|
177
|
+
"types": "./esm/src/geo/client.d.ts",
|
|
178
|
+
"import": "./esm/src/geo/client.js"
|
|
179
|
+
},
|
|
180
|
+
"./geo/places": {
|
|
181
|
+
"types": "./esm/src/geo/places.d.ts",
|
|
182
|
+
"import": "./esm/src/geo/places.js"
|
|
183
|
+
},
|
|
160
184
|
"./files": {
|
|
161
185
|
"types": "./esm/src/files/mod.d.ts",
|
|
162
186
|
"import": "./esm/src/files/mod.js"
|
package/skills/loom/SKILL.md
CHANGED
|
@@ -204,18 +204,36 @@ as more authoritative than a generic mapped error when deciding what failed.
|
|
|
204
204
|
a tradeoff.
|
|
205
205
|
- Do not add comments for obvious assignments or control flow.
|
|
206
206
|
|
|
207
|
-
## Verification
|
|
208
|
-
|
|
209
|
-
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
207
|
+
## Verification and working branches
|
|
208
|
+
|
|
209
|
+
- Default to an isolated topic branch and worktree for code changes. Direct work
|
|
210
|
+
on the default/protected branch needs explicit user authorization naming that
|
|
211
|
+
branch (a generic "commit this" does not) and an independently owned checkout
|
|
212
|
+
with no unrelated or user-owned changes; never switch a shared checkout.
|
|
213
|
+
- Intermediate commits on isolated branches need passing affected tests and
|
|
214
|
+
relevant type, lint, translation and feature checks. Record what ran and which
|
|
215
|
+
full/final gates are pending; these checkpoints are not merge-ready evidence.
|
|
216
|
+
- Before declaring a code-changing feature complete or ready for review/merge,
|
|
217
|
+
pass the full local suite and required quality/build/runtime gates on the final
|
|
218
|
+
candidate. Verify the actual merge candidate if the target branch has moved.
|
|
219
|
+
In the Loom repository use its recorded full gates; consumers use
|
|
220
|
+
`project.tooling`.
|
|
221
|
+
- Before every direct default/protected-branch commit, pass the full suite and
|
|
222
|
+
required gates for that exact commit, including direct prose-only commits.
|
|
223
|
+
User authorization for Main work does not waive verification. Agent-performed
|
|
224
|
+
local merges, squashes, fast-forwards, cherry-picks and rebases onto that branch
|
|
225
|
+
require the same authorization and full verification of the resulting tree.
|
|
226
|
+
- Broaden checks earlier for shared contracts, generated output, tooling,
|
|
227
|
+
authentication, persistence or uncertain impact. Choose coherent feature
|
|
228
|
+
checkpoints rather than repeated full runs for unused microsteps.
|
|
229
|
+
- Format first. Reuse evidence only while its tested inputs and relevant
|
|
230
|
+
environment remain unchanged. Later code edits invalidate a prior final/full
|
|
231
|
+
result. Compare staged and working content; use an isolated snapshot when
|
|
232
|
+
user-owned changes differ, without stashing or resetting them.
|
|
233
|
+
- Read [verification workflow](references/verification-workflow.md) when choosing
|
|
234
|
+
branch/Main checkpoints, sharing incomplete work, reusing final evidence or
|
|
235
|
+
reducing test cost. It distinguishes deferred full checks from failing checks
|
|
236
|
+
and preserves the existing database test tiers.
|
|
219
237
|
- Ordinary prose changes need formatting and reference checks. Packaged skills,
|
|
220
238
|
catalog metadata, activation logic, and reference moves also need relevant
|
|
221
239
|
skill/catalog tests and verification that references ship and resolve.
|
|
@@ -226,9 +244,8 @@ as more authoritative than a generic mapped error when deciding what failed.
|
|
|
226
244
|
integrity. Recommendations are optional; checking does not authorize adoption.
|
|
227
245
|
- Use runtime verification for affected Next.js behavior when a server is
|
|
228
246
|
running. Keep required build, browser-type, integration, CI and release gates
|
|
229
|
-
intact. In Loom, `bun run check`
|
|
230
|
-
|
|
231
|
-
Oxc quality plus Deno parity; use `bun run format` for formatting/import order
|
|
247
|
+
intact. In the Loom repository, `bun run check` is the full gate described in
|
|
248
|
+
the linked workflow; use `bun run format` for formatting/import order
|
|
232
249
|
and explicit `bun run lint:fix` for safe lint fixes. Never put suggestion or
|
|
233
250
|
dangerous lint fixes in format/save/CI. Consumer tools remain independently
|
|
234
251
|
recorded.
|
|
@@ -236,6 +253,17 @@ as more authoritative than a generic mapped error when deciding what failed.
|
|
|
236
253
|
guidance overlaps. Use feature-specific Loom skills for affected active
|
|
237
254
|
features.
|
|
238
255
|
|
|
256
|
+
## Heavy local work
|
|
257
|
+
|
|
258
|
+
On a shared Linux workstation, heavy steps (Vitest suites, `next build`)
|
|
259
|
+
from every Loom consumer draw CPUs from one machine-wide pool. Where the app
|
|
260
|
+
wraps its heavy tasks with `loom slots run`, run those tasks as recorded; do
|
|
261
|
+
not bypass the wrapper, and never add `--allow-unpooled` on your own. A task
|
|
262
|
+
that waits is queued behind other work: `loom slots status` shows who holds
|
|
263
|
+
the CPUs and who is ahead. Configs read `LOOM_SLOTS` for their worker counts
|
|
264
|
+
(Vitest `maxWorkers`, Next `experimental.cpus`). See `docs/machine-slots.md`
|
|
265
|
+
in the Loom repository.
|
|
266
|
+
|
|
239
267
|
## Local development
|
|
240
268
|
|
|
241
269
|
Use `loom dev local <path>` and `loom dev sync` for unpublished package work.
|