<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: kohei matsunobu</title>
    <description>The latest articles on DEV Community by kohei matsunobu (@koheip).</description>
    <link>https://dev.to/koheip</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4190326%2F1903be46-5d21-4631-9c60-2ad32b3a8b7b.jpg</url>
      <title>DEV Community: kohei matsunobu</title>
      <link>https://dev.to/koheip</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/koheip"/>
    <language>en</language>
    <item>
      <title>An Introduction to RevenueCat for Indie Developers</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Fri, 27 Nov 2026 15:37:32 +0000</pubDate>
      <link>https://dev.to/koheip/an-introduction-to-revenuecat-for-indie-developers-2oa6</link>
      <guid>https://dev.to/koheip/an-introduction-to-revenuecat-for-indie-developers-2oa6</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I'm Kohei Matsunobu, a second-year student at ZEN University studying intelligent informatics. I build iOS apps as a personal project.&lt;/p&gt;

&lt;p&gt;Once you add subscriptions or one-time purchases to an app, the work grows quickly: receipt validation, renewal and cancellation state, different product IDs on iOS and Android, and the paywall itself. RevenueCat is a service that provides that billing infrastructure as an SDK and a backend.&lt;/p&gt;

&lt;p&gt;This article is an introduction for indie developers. Pricing, the free tier, SDK names, commands, and APIs are limited to what I could verify in RevenueCat's official site and documentation. I have left out anything I could not verify. API keys in the code samples are placeholders only. This is not a usage report, and it does not include any app-specific experience or revenue figures.&lt;/p&gt;

&lt;h2&gt;
  
  
  What RevenueCat is
&lt;/h2&gt;

&lt;p&gt;RevenueCat's documentation describes it as a backend and SDKs that wrap StoreKit, Google Play Billing, and RevenueCat Billing, so you can implement in-app and web purchases and subscriptions without maintaining your own IAP infrastructure. With the SDK, you can manage purchases across platforms.&lt;/p&gt;

&lt;p&gt;In the official Implementation Responsibilities guide, RevenueCat is the single source of truth for subscription status across iOS, Android, and web. Receipt validation and the work of talking to native frameworks such as Apple's StoreKit and Google's BillingClient are handled automatically when you use the SDK.&lt;/p&gt;

&lt;p&gt;RevenueCat is not a payment processor. The pricing FAQ answers "Does RevenueCat pay me?" by stating that you continue to be paid by Apple, Google, Stripe, or any other payment provider you integrate with RevenueCat. Creating products, presenting them to users, and unlocking paid features remain the developer's responsibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  What gets easier for indie developers
&lt;/h2&gt;

&lt;p&gt;For a solo developer, standing up and maintaining a billing server can crowd out work on the product itself. These are the parts of that burden that official docs describe RevenueCat as taking on.&lt;/p&gt;

&lt;h3&gt;
  
  
  You do not have to run your own receipt-validation server
&lt;/h3&gt;

&lt;p&gt;After a purchase, the SDK sends the purchase token or receipt to RevenueCat's backend. The backend verifies it with the store and returns the customer's state (&lt;code&gt;CustomerInfo&lt;/code&gt;). The Implementation Responsibilities guide assigns syncing, parsing, and verifying receipts, tracking entitlement status, and tracking purchase history to RevenueCat.&lt;/p&gt;

&lt;p&gt;That means you do not have to implement Apple or Google server-side validation yourself, or maintain a server that recomputes subscription state on every renewal or expiration. If you serve premium content from your own server, though, you should not trust the client alone. Confirm access on the server with webhooks or the REST API, as described later.&lt;/p&gt;

&lt;h3&gt;
  
  
  You can treat iOS and Android purchases together
&lt;/h3&gt;

&lt;p&gt;A single project can connect to more than one store, such as the Apple App Store and Google Play. A user's entitlements are shared across all apps in the same project. In app code, you can check an entitlement such as whether &lt;code&gt;pro&lt;/code&gt; is active, instead of tracking every store-specific product identifier yourself.&lt;/p&gt;

&lt;p&gt;Hybrid SDKs such as React Native and Flutter need a separate public API key for each platform (iOS and Android). The keys are in the dashboard under Project Settings &amp;gt; API keys &amp;gt; App specific keys.&lt;/p&gt;

&lt;h3&gt;
  
  
  Entitlements, Offerings, and Products
&lt;/h3&gt;

&lt;p&gt;Three concepts show up throughout the official docs.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Product&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The individual SKU a user actually buys. In production, you set price and duration in App Store Connect, Google Play Console, or another store, then import the product into RevenueCat&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Entitlement&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A level of access, features, or content the user is entitled to. You attach purchased products to it. App code checks this identifier rather than a list of product IDs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Offering&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The set of products shown on a paywall. A &lt;strong&gt;Package&lt;/strong&gt; inside an offering groups equivalent products across iOS, Android, and web&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The docs say most apps need only one entitlement, for example &lt;code&gt;pro&lt;/code&gt;. If you have tiers such as Gold and Platinum, you create more than one. A subscription product unlocks an entitlement for the subscription duration. Non-consumable purchases, and consumable purchases that you attach to an entitlement, unlock that content permanently. The docs also note that you often should not attach consumables—such as extra lives in a game—to an entitlement.&lt;/p&gt;

&lt;p&gt;Using Offerings is optional, but they are required for Paywalls, Experiments, and Targeting. You choose a Default Offering in the dashboard. If your paywall reads the &lt;code&gt;current&lt;/code&gt; offering returned by &lt;code&gt;getOfferings&lt;/code&gt;, you can change which products you present without shipping an app update. RevenueCat strongly recommends using &lt;code&gt;current&lt;/code&gt; rather than hardcoding an identifier.&lt;/p&gt;

&lt;p&gt;During development, you can create products in RevenueCat's Test Store and try the purchase flow without connecting a store. For production, create products in each store and import them with Import Products in the dashboard. The docs also state that if a user buys a product that has not been set up in RevenueCat, the transaction is still tracked and the product is created automatically.&lt;/p&gt;

&lt;h3&gt;
  
  
  Paywalls you can change from the dashboard
&lt;/h3&gt;

&lt;p&gt;RevenueCat Paywalls let you remotely configure the paywall view without code changes or app updates. A paywall is attached to an Offering. The official docs describe building one from a template, from scratch, with the AI Editor, or by importing from Figma. A paywall can be a single screen or a multi-step flow, which is useful for onboarding.&lt;/p&gt;

&lt;p&gt;In the app, you install the RevenueCat UI SDK, create a paywall for the Offering you want to serve, and present it. On iOS the UI package is &lt;code&gt;RevenueCatUI&lt;/code&gt;. In React Native and Expo it is &lt;code&gt;react-native-purchases-ui&lt;/code&gt;. RevenueCat Paywalls include a Restore Purchases button by default, so you do not have to write restore code unless you build your own paywall.&lt;/p&gt;

&lt;p&gt;There are limits. According to the Paywalls documentation, supported platforms are iOS 15.0 and later, Android 7.0 (API 24) and later, Mac Catalyst 15.0 and later, macOS 12.0 and later, and web via Web Purchase Links. watchOS, tvOS, and visionOS are not supported. Each SDK has a recommended minimum version, and some features, such as multi-step paywalls, require a newer version. Those version numbers can change, so check the official table when you integrate.&lt;/p&gt;

&lt;h3&gt;
  
  
  The dashboard and metrics
&lt;/h3&gt;

&lt;p&gt;The Overview page in the dashboard includes these cards:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Active Trials (currently tracked free trials)&lt;/li&gt;
&lt;li&gt;Active Subscriptions (currently tracked paid subscriptions)&lt;/li&gt;
&lt;li&gt;MRR (monthly recurring revenue)&lt;/li&gt;
&lt;li&gt;Revenue (gross revenue in the last 28 days, before store fees and taxes)&lt;/li&gt;
&lt;li&gt;New Customers (App User IDs created in the past 28 days)&lt;/li&gt;
&lt;li&gt;Active Customers (App User IDs that communicated with RevenueCat in the past 28 days)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The docs say that for most customers, subscription metrics update in real time, while New Customers and Active Customers may be cached for 1–2 hours. You can toggle between sandbox and production data. Charts, however, show production transaction data only, because of limitations in sandbox environments.&lt;/p&gt;

&lt;p&gt;Charts are built from purchase data stored in RevenueCat and do not rely on client-side event logging. The docs also note that figures may not match Apple, Google, or Stripe exactly. For tax reporting, use the payment processor's data, not RevenueCat's. Dates and times in the dashboard are in UTC unless explicitly specified.&lt;/p&gt;

&lt;h3&gt;
  
  
  Webhooks to your own server
&lt;/h3&gt;

&lt;p&gt;If you want your backend to stay in sync with purchases and subscription state changes, use webhooks. You register an HTTPS endpoint under Integrations in the dashboard, and RevenueCat sends a JSON &lt;code&gt;POST&lt;/code&gt;. Your server should return HTTP 200; any other status is treated as a failure. Failed deliveries are retried up to five times with exponential backoff, for a cumulative retry window of about 80 minutes. If the response takes longer than 60 seconds, RevenueCat disconnects, so the docs recommend returning 200 first and doing the work afterward.&lt;/p&gt;

&lt;p&gt;Official examples of what you can do with webhooks include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keeping an up-to-date record of subscriptions and purchases in your own backend&lt;/li&gt;
&lt;li&gt;Triggering automations from the subscription lifecycle&lt;/li&gt;
&lt;li&gt;Reminding subscribers when they cancel, or notifying them about billing issues&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;RevenueCat recommends setting an authorization header, optionally enabling HMAC signatures (&lt;code&gt;X-RevenueCat-Webhook-Signature&lt;/code&gt;), and handling duplicate events idempotently (delivery is at least once). For syncing state, the docs recommend calling the REST API &lt;code&gt;GET /subscribers&lt;/code&gt; after any webhook, rather than writing custom logic for every event type.&lt;/p&gt;

&lt;p&gt;Webhooks are a Pro feature. The current self-serve default plan is Pro, which is free up to the revenue threshold described below. If you are on a legacy plan without webhook access, the docs ask you to migrate to the new Pro plan.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pricing
&lt;/h2&gt;

&lt;p&gt;This section follows the &lt;a href="https://www.revenuecat.com/pricing" rel="noopener noreferrer"&gt;Pricing&lt;/a&gt; page and the billing documentation. It reflects what those pages said when I checked them. Confirm the official pricing page before you rely on it, because it can change.&lt;/p&gt;

&lt;p&gt;The current self-serve offering is a single standard plan, Pro, rather than a set of feature-gated tiers. The pricing page says the full suite of features comes standard, and that it is free to get started.&lt;/p&gt;

&lt;p&gt;Billing is based on &lt;strong&gt;Monthly Tracked Revenue (MTR)&lt;/strong&gt;. MTR is the revenue RevenueCat tracks, in USD, during a one-month billing period, before the platform cut. It is the amount charged to the customer, not your net proceeds after store fees and taxes. It includes paid subscriptions, renewals, and one-time purchases. It is not the same as MRR. Billing periods do not follow the calendar month; they run from the same date in one month to the same date in the next (for example, July 15 to August 15).&lt;/p&gt;

&lt;p&gt;On the Pro plan:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Months when MTR is &lt;strong&gt;under $2,500&lt;/strong&gt; are free&lt;/li&gt;
&lt;li&gt;Months when MTR is &lt;strong&gt;over $2,500&lt;/strong&gt; are billed at &lt;strong&gt;1% of total MTR&lt;/strong&gt; for that period (not 1% of only the amount above the threshold)&lt;/li&gt;
&lt;li&gt;Official examples: $2,500 MTR is billed as $25; $2,600 MTR is billed as $26&lt;/li&gt;
&lt;li&gt;If MTR falls back below $2,500 in a later month, that month is free again&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A credit card is optional at sign-up. If you reach $2,500 MTR without card details on file, parts of the product become unavailable until you add them. If you exceed the limit in your first month, you get a 30-day grace period from the moment you reach it. If you exceed it in a later month, access is restricted immediately until payment succeeds. Restricted abilities include viewing and filtering Charts, creating or exporting Customer Lists, viewing Customer History (Customer Details remain available), viewing individual events, creating new paywalls, and editing existing paywalls (using existing paywalls remains available).&lt;/p&gt;

&lt;p&gt;Enterprise pricing is negotiated and depends on commitment, MTR, features, and support. This article does not quote Enterprise prices.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to get started
&lt;/h2&gt;

&lt;p&gt;This is an overview of the official flow and the caveats I could verify, not a click-by-click tutorial.&lt;/p&gt;

&lt;p&gt;The usual sequence is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a RevenueCat account and project&lt;/li&gt;
&lt;li&gt;Prepare App Store Connect (and Google Play Console, if you ship on Android)&lt;/li&gt;
&lt;li&gt;Connect the store in RevenueCat, then configure Products, Entitlements, and Offerings&lt;/li&gt;
&lt;li&gt;Install the SDK and configure it with your public API key&lt;/li&gt;
&lt;li&gt;Optionally create a paywall in the dashboard and present it from the app&lt;/li&gt;
&lt;li&gt;Test, then switch from the Test Store API key to the platform-specific public API key before you submit for review&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  App Store Connect setup
&lt;/h3&gt;

&lt;p&gt;Using RevenueCat does not remove the Apple-side work. The official App Store Connect setup guide includes these prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enroll in the Apple Developer Program&lt;/li&gt;
&lt;li&gt;Accept the Paid Applications Agreement under Agreements, Tax, and Banking in App Store Connect&lt;/li&gt;
&lt;li&gt;Add banking and tax information&lt;/li&gt;
&lt;li&gt;Register a Bundle ID and enable the In-App Purchase capability&lt;/li&gt;
&lt;li&gt;Create the app record in App Store Connect (it must match the Bundle ID in Xcode)&lt;/li&gt;
&lt;li&gt;For subscriptions, create a Subscription Group and add products (Product ID, price, duration, and localizations)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For sandbox testing, create testers in App Store Connect under Users and Access &amp;gt; Sandbox Testers. When you first submit an app with subscriptions, you must include the in-app purchases in the same app version submission. The official guide stresses that they will not be reviewed otherwise. The first consumable, non-consumable, auto-renewable subscription, and non-renewing subscription must each be submitted with an app version.&lt;/p&gt;

&lt;p&gt;To connect an Apple App Store app in RevenueCat, you add the app name, Bundle ID, Shared Secret, and In-App Purchase Key. Adding an App Store Connect API key is also recommended, so you can import products and prices from App Store Connect.&lt;/p&gt;

&lt;p&gt;Official docs describe the credentials this way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;App-Specific Shared Secret&lt;/strong&gt;: required for receipt validation with StoreKit 1. Apple has deprecated StoreKit 1, and new apps are recommended to use StoreKit 2&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;In-App Purchase Key&lt;/strong&gt;: required for StoreKit 2 and RevenueCat Purchases v5.x and later (for example, iOS SDK 5.0.0+ and React Native SDK 8.0.0+). Without it, transactions may fail to be recorded, and users may not get access to what they bought. Generate it in App Store Connect under Users and Access → Integrations → In-App Purchase, upload the downloaded &lt;code&gt;.p8&lt;/code&gt; file to RevenueCat, and enter the Issuer ID. You can use the same key for all App Store apps under the same App Store Connect account&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;App Store Connect API Key&lt;/strong&gt;: used to import products and prices. Create a key with at least App Manager access under Users and Access → Integrations → App Store Connect API, and upload it with Apple's original filename, &lt;code&gt;AuthKey_XXXXXXXXXX.p8&lt;/code&gt;. You will also need the Issuer ID and the Vendor number from the top left of Payments and Financial Reports. This is not the same file as the In-App Purchase Key (&lt;code&gt;SubscriptionKey_XXXXXXXXXX.p8&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Xcode, add the In-App Purchase capability under Signing &amp;amp; Capabilities. If you are only testing with the Test Store, you can come back to this step when you connect the App Store.&lt;/p&gt;

&lt;p&gt;After you connect a store, RevenueCat recommends setting up Platform Server Notifications, so purchase and subscription events reach RevenueCat sooner and webhook and integration delivery is faster.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing the SDK in Swift
&lt;/h3&gt;

&lt;p&gt;For iOS and other Apple platforms, the official recommended install method is Swift Package Manager. CocoaPods and Carthage are also documented for projects that already use them.&lt;/p&gt;

&lt;p&gt;In Xcode, choose File &amp;gt; Add Package Dependencies and paste this repository URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://github.com/RevenueCat/purchases-ios-spm.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set the dependency rule to Up to Next Major Version, starting from &lt;code&gt;5.0.0&lt;/code&gt;. Add the RevenueCat product to your app target, and add RevenueCatUI as well if you want paywalls or other UI components. To verify the install, add &lt;code&gt;import RevenueCat&lt;/code&gt; and confirm that the project builds.&lt;/p&gt;

&lt;p&gt;Configure the SDK once, early in the app lifecycle, and only with a public API key. Never embed a secret API key (the ones that start with &lt;code&gt;sk_&lt;/code&gt;) in an app or website.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;RevenueCat&lt;/span&gt;

&lt;span class="c1"&gt;// Call this once, early in launch, for example in application(_:didFinishLaunchingWithOptions:)&lt;/span&gt;
&lt;span class="nc"&gt;Purchases&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logLevel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;debug&lt;/span&gt;
&lt;span class="nc"&gt;Purchases&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;withAPIKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;revenuecat_project_apple_api_key&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;appUserID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;app_user_id&amp;gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;&amp;lt;revenuecat_project_apple_api_key&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;app_user_id&amp;gt;&lt;/code&gt; are placeholders. Public keys are listed under API keys in the dashboard. For how &lt;code&gt;appUserID&lt;/code&gt; works, including anonymous users and attaching your own user identifiers, see the official Identifying Users guide.&lt;/p&gt;

&lt;p&gt;Check subscription status with &lt;code&gt;getCustomerInfo&lt;/code&gt; and inspect whether the relevant entitlements are active. Fetch offerings with &lt;code&gt;getOfferings&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing the SDK in React Native and Expo
&lt;/h3&gt;

&lt;p&gt;In React Native and Expo, the core package is &lt;code&gt;react-native-purchases&lt;/code&gt;, and UI components such as Paywalls and Customer Center are in &lt;code&gt;react-native-purchases-ui&lt;/code&gt;. These packages already include the RevenueCat iOS SDK, so do not also add &lt;code&gt;purchases-ios&lt;/code&gt; or &lt;code&gt;purchases-ios-spm&lt;/code&gt; to your Xcode project. Doing so can cause duplicate package errors or version conflicts.&lt;/p&gt;

&lt;p&gt;For a &lt;strong&gt;React Native&lt;/strong&gt; app that is not an Expo project, the official prerequisite is React Native 0.80 or later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install --save react-native-purchases react-native-purchases-ui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With yarn, use &lt;code&gt;yarn add react-native-purchases react-native-purchases-ui&lt;/code&gt;. The React Native CLI installs the iOS CocoaPods dependencies automatically the first time you run the app. To verify the install, add &lt;code&gt;import Purchases from 'react-native-purchases'&lt;/code&gt; and confirm that &lt;code&gt;npx react-native run-ios&lt;/code&gt; or &lt;code&gt;npx react-native run-android&lt;/code&gt; succeeds. Enable the In-App Purchase capability in Xcode when you are ready to distribute on the App Store. You do not need that capability to build and test with the Test Store.&lt;/p&gt;

&lt;p&gt;The official &lt;strong&gt;Expo&lt;/strong&gt; guide assumes Expo SDK 54 or later. To use and test RevenueCat with Expo, you need an Expo development build.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx expo install expo-dev-client
npx expo install react-native-purchases react-native-purchases-ui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you install the packages, a full build is required; hot reloading is not enough. The docs say that skipping the build can produce errors such as &lt;code&gt;Invariant Violation: new NativeEventEmitter() requires a non-null argument.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Because this is a hybrid SDK, configure it with a separate public API key per platform. The values below are placeholders.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Platform&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react-native'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Purchases&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;LOG_LEVEL&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'react-native-purchases'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Purchases&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setLogLevel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;LOG_LEVEL&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;VERBOSE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Platform&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;OS&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'ios'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nc"&gt;Purchases&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;revenuecat_project_apple_api_key&amp;gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Platform&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;OS&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'android'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nc"&gt;Purchases&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;revenuecat_project_google_api_key&amp;gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fetching customer info and checking an entitlement looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;customerInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Purchases&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getCustomerInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="n"&gt;customerInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;entitlements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;my_entitlement_identifier&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s2"&gt;"undefined"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// The entitlement is active&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Failed to fetch customer info&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Expo Go does not run real in-app purchases
&lt;/h4&gt;

&lt;p&gt;The official Expo guide is explicit about Expo Go. Expo Go is a sandbox that cannot run custom native code, including the native modules required for in-app purchases. &lt;code&gt;react-native-purchases&lt;/code&gt; does include a Preview API Mode for Expo Go. In that environment, native calls are replaced with JavaScript-level mock APIs, so the app can load and run subscription-related logic without crashing. Real purchases do not work in this mode.&lt;/p&gt;

&lt;p&gt;That is useful for previewing subscription UI and integration flow. To test in-app purchases and use real RevenueCat functionality, you must use a development build. For the iOS Simulator, the official guide walks through an EAS build with an &lt;code&gt;ios-simulator&lt;/code&gt; profile.&lt;/p&gt;

&lt;p&gt;As a related note, React Native SDK version 12 will require Swift Package Manager for RevenueCat's iOS dependencies. The docs currently describe SPM support in React Native and Expo as experimental, and the CocoaPods instructions apply to SDK 11. Check the official migration notes before you upgrade.&lt;/p&gt;

&lt;h2&gt;
  
  
  When it may not fit, and other caveats
&lt;/h2&gt;

&lt;p&gt;Whether RevenueCat is a good fit depends on how you want to own billing. These points come from official documentation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The stores still process payments.&lt;/strong&gt; RevenueCat is not a payment processor. You still have to complete the Paid Applications Agreement, banking and tax setup, product creation, and app review in App Store Connect (or Google Play). Installing RevenueCat does not replace that store-side work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unlocking paid features is still your job.&lt;/strong&gt; RevenueCat reports entitlement status; unlocking content and downloading purchased content are the developer's responsibility. If premium content is served from your server, the docs say not to trust the client alone—confirm access with webhooks or the REST API. Authenticate the REST API with a secret API key, and keep that key on the server only.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expo Go cannot make real purchases.&lt;/strong&gt; Preview API Mode can run logic, but you need a development build to test purchases.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Paywalls are not available on every Apple platform.&lt;/strong&gt; watchOS, tvOS, and visionOS are officially unsupported. If you need a paywall there, you will need another approach, such as a custom UI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Metrics may not match store reports.&lt;/strong&gt; Charts use production transactions only. Differences can come from metric definitions or estimated currency conversion. Use the payment processor's data for tax reporting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The 1% fee is calculated on MTR before store commission.&lt;/strong&gt; It is not 1% of your net proceeds. Months under $2,500 are free; months over that threshold are billed at 1% of total MTR.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leaving later means taking validation and state management back in-house.&lt;/strong&gt; The official shutdown steps say to remove the SDK and, if needed, set up your own purchase validation and subscription management before you delete the project. Deleting a project is immediate and irreversible. Users on older app versions will lose access to RevenueCat services. Active customer subscriptions are not canceled when you delete the account.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not submit with the wrong API key.&lt;/strong&gt; If you developed against the Test Store, switch from the Test Store API key to the platform-specific public API key before app review.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A purchase will not unlock access if you forget to attach the product to an entitlement.&lt;/strong&gt; When you add a new product, attach it to the right entitlement. For consumables, check the official guidance on whether an entitlement is appropriate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also implement StoreKit or Google Play Billing yourself and run your own validation server. If you already have a stable custom stack, or you do not want a third-party dependency, you do not have to use RevenueCat. As an introduction, it is a service to consider when you would rather not build receipt validation, cross-platform status, a dashboard, and remotely configurable paywalls from scratch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;RevenueCat provides SDKs and a backend for validating in-app purchases and subscriptions, tracking entitlement status, and analyzing the results. For indie developers, the main points are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can start without running your own receipt-validation server or subscription-state machine&lt;/li&gt;
&lt;li&gt;Entitlements let you treat iOS and Android products as one access model&lt;/li&gt;
&lt;li&gt;Paywalls, Charts, and webhooks cover a lot of the operational work from the dashboard&lt;/li&gt;
&lt;li&gt;At the time I checked the docs, Pro features are free below $2,500 MTR per month, and months above that are billed at 1% of MTR (before store commission)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Store agreements, product setup, and review still sit with you, and unlocking paid features is still your app's and your server's responsibility. Expo Go cannot complete real purchases; use a development build. Put only public API keys in the app, and keep secret keys on a server.&lt;/p&gt;

&lt;p&gt;For integration details, and for pricing or SDK versions that may change after this article, treat the official documentation below as the source of truth.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/pricing" rel="noopener noreferrer"&gt;RevenueCat Pricing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/welcome/set-up-revenuecat/account-management" rel="noopener noreferrer"&gt;Billing and account settings&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/getting-started/installation/expo" rel="noopener noreferrer"&gt;What is RevenueCat, in the Expo guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/getting-started/quickstart" rel="noopener noreferrer"&gt;SDK Quickstart&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/getting-started/configuring-sdk" rel="noopener noreferrer"&gt;Configuring the SDK&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/getting-started/installation/ios" rel="noopener noreferrer"&gt;iOS &amp;amp; Apple Platforms (SDK install)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/getting-started/installation/reactnative" rel="noopener noreferrer"&gt;React Native (SDK install)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/getting-started/installation/expo" rel="noopener noreferrer"&gt;Expo (SDK install and Expo Go notes)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/platform-resources/implementation-responsibilities" rel="noopener noreferrer"&gt;Implementation Responsibilities&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/offerings/products-overview" rel="noopener noreferrer"&gt;Products Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/getting-started/entitlements" rel="noopener noreferrer"&gt;Entitlements&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/offerings/overview" rel="noopener noreferrer"&gt;Offerings&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/tools/paywalls" rel="noopener noreferrer"&gt;Paywalls&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/tools/paywalls/creating-paywalls" rel="noopener noreferrer"&gt;Creating Paywalls&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/dashboard-and-metrics/overview" rel="noopener noreferrer"&gt;Overview Metrics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/dashboard-and-metrics/charts" rel="noopener noreferrer"&gt;Charts Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/integrations/webhooks" rel="noopener noreferrer"&gt;Webhooks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/projects/authentication" rel="noopener noreferrer"&gt;API Keys / Authentication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/projects/connect-a-store" rel="noopener noreferrer"&gt;Connect Apps &amp;amp; Web Providers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/platform-resources/apple-platform-resources/app-store-connect-setup-guide" rel="noopener noreferrer"&gt;App Store Connect Setup Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/store-configuration/app-store/service-credentials-index" rel="noopener noreferrer"&gt;App Store Service Credentials&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/service-credentials/itunesconnect-app-specific-shared-secret/in-app-purchase-key-configuration" rel="noopener noreferrer"&gt;In-App Purchase Key Configuration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/service-credentials/itunesconnect-app-specific-shared-secret" rel="noopener noreferrer"&gt;App-Specific Shared Secret&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/docs/service-credentials/itunesconnect-app-specific-shared-secret/app-store-connect-api-key-configuration" rel="noopener noreferrer"&gt;App Store Connect API Key Configuration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.revenuecat.com/feature/infrastructure" rel="noopener noreferrer"&gt;Infrastructure (server-side receipt validation)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>revenuecat</category>
      <category>ios</category>
      <category>reactnative</category>
      <category>expo</category>
    </item>
    <item>
      <title>How I Connect MCP Servers in Claude Code, Codex, and Cursor</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Thu, 26 Nov 2026 07:28:19 +0000</pubDate>
      <link>https://dev.to/koheip/how-i-connect-mcp-servers-in-claude-code-codex-and-cursor-5ahe</link>
      <guid>https://dev.to/koheip/how-i-connect-mcp-servers-in-claude-code-codex-and-cursor-5ahe</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I'm a second-year student at ZEN University studying intelligent informatics, and I want to become an AI engineer. I build personal projects alongside my studies.&lt;/p&gt;

&lt;p&gt;Day to day I work on Windows with Claude Code, Codex CLI, and Cursor. I often connect MCP servers so I can work with issues, docs, and external services without pasting the same context into chat. The catch is that each client stores the configuration in a different place and uses a different add command.&lt;/p&gt;

&lt;p&gt;This article is a setup note for myself, limited to how I connect MCP servers. Command names, config-file locations, and flags are taken from official documentation I checked. I have left out anything I could not verify. Token values in the examples are placeholders only.&lt;/p&gt;

&lt;h2&gt;
  
  
  What MCP is
&lt;/h2&gt;

&lt;p&gt;The Model Context Protocol (MCP) is an open protocol for connecting an AI application to external tools and data sources. A host—an AI application such as Claude Code or Cursor—holds a client connection for each MCP server, and can then use the tools and resources that server provides.&lt;/p&gt;

&lt;p&gt;The official architecture overview describes the roles this way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Host&lt;/strong&gt;: the AI application that coordinates the connections&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client&lt;/strong&gt;: the component that maintains the connection to one MCP server&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server&lt;/strong&gt;: the program that provides tools or context&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;"MCP server" refers to the program that serves context, not to where it runs. A process started on your own machine and a server hosted in the cloud are both MCP servers.&lt;/p&gt;

&lt;p&gt;The reason to connect one is simple: instead of pasting information from another system into chat, Claude, Codex, or Cursor can use that system directly. Only connect servers you trust. A server that fetches external content can also expose you to prompt-injection risk.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two ways to connect: stdio and remote (HTTP / OAuth)
&lt;/h2&gt;

&lt;p&gt;The MCP specification focuses on two transports:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;How it works&lt;/th&gt;
&lt;th&gt;How authentication works&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;stdio&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The host starts a local process and talks to it over standard input and output&lt;/td&gt;
&lt;td&gt;Do not use the MCP OAuth flow. Pass any required keys through environment variables or similar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Streamable HTTP&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The host connects over HTTP to a remote server, or to an HTTP endpoint you run locally&lt;/td&gt;
&lt;td&gt;Bearer tokens, API keys, custom headers, or OAuth. MCP recommends OAuth&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;stdio suits tools that need direct access to your machine, such as the filesystem or local commands. Remote HTTP suits endpoints that a service hosts, such as GitHub or Notion.&lt;/p&gt;

&lt;p&gt;Two footnotes are worth keeping in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Some clients can still connect to older &lt;strong&gt;SSE&lt;/strong&gt; endpoints. Claude Code's documentation marks the SSE transport as deprecated and tells you to use HTTP when it is available.&lt;/li&gt;
&lt;li&gt;OAuth in the MCP specification is for HTTP-based transports. A stdio server should not use that flow; it should take credentials from the environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a server needs a key, it is safer not to put the value itself in a config file or a command that will be stored in shell history. Leave only the variable name in the config: &lt;code&gt;--env&lt;/code&gt; or &lt;code&gt;${API_KEY}&lt;/code&gt; in Claude Code, &lt;code&gt;env_vars&lt;/code&gt; or &lt;code&gt;bearer_token_env_var&lt;/code&gt; in Codex, and &lt;code&gt;${env:API_KEY}&lt;/code&gt; in Cursor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding a server in Claude Code
&lt;/h2&gt;

&lt;p&gt;In Claude Code, the basic command is &lt;code&gt;claude mcp add&lt;/code&gt;. Where the configuration is stored depends on the scope.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scope&lt;/th&gt;
&lt;th&gt;Loads in&lt;/th&gt;
&lt;th&gt;Shared with the team&lt;/th&gt;
&lt;th&gt;Stored in&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;local&lt;/strong&gt; (default)&lt;/td&gt;
&lt;td&gt;The current project only&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;~/.claude.json&lt;/code&gt;, under that project's entry&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;project&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The current project only&lt;/td&gt;
&lt;td&gt;Yes, through version control&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;.mcp.json&lt;/code&gt; at the project root&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;user&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;All of your projects&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;&lt;code&gt;~/.claude.json&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Local scope is stored in &lt;code&gt;~/.claude.json&lt;/code&gt; in your home directory. That is not the same file as &lt;code&gt;.claude/settings.local.json&lt;/code&gt; inside a project. On Windows, when official docs write &lt;code&gt;~&lt;/code&gt;, they mean a path under your user profile directory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remote HTTP servers
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude mcp add --transport http &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;name&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;url&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;# Example&lt;/span&gt;
claude mcp add --transport http notion https://mcp.notion.com/mcp

&lt;span class="c"&gt;# Passing a bearer token in a header (placeholder value)&lt;/span&gt;
claude mcp add --transport http secure-api https://api.example.com/mcp --header &lt;span class="s2"&gt;"Authorization: Bearer YOUR_TOKEN"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In JSON, set &lt;code&gt;type&lt;/code&gt; to &lt;code&gt;http&lt;/code&gt;. &lt;code&gt;streamable-http&lt;/code&gt; is accepted as an alias for &lt;code&gt;http&lt;/code&gt;. An entry that has a &lt;code&gt;url&lt;/code&gt; but no &lt;code&gt;type&lt;/code&gt; is read as a stdio server and fails.&lt;/p&gt;

&lt;p&gt;If a service still exposes only SSE, use &lt;code&gt;--transport sse&lt;/code&gt;. From Claude Code v2.1.265, a server added with &lt;code&gt;--transport http&lt;/code&gt; may fall back to SSE if the server does not accept HTTP. The docs still recommend HTTP when it is available.&lt;/p&gt;

&lt;h3&gt;
  
  
  Local stdio servers
&lt;/h3&gt;

&lt;p&gt;For stdio servers, separate Claude Code's own options from the command that starts the server with &lt;code&gt;--&lt;/code&gt;. Everything after &lt;code&gt;--&lt;/code&gt; is passed to the server command unchanged.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude mcp add --env &lt;span class="nv"&gt;AIRTABLE_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YOUR_KEY --transport stdio airtable -- npx -y airtable-mcp-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the server name comes immediately after &lt;code&gt;--env&lt;/code&gt;, the CLI reads the name as another &lt;code&gt;KEY=value&lt;/code&gt; pair and rejects it. Put another option, such as &lt;code&gt;--transport stdio&lt;/code&gt;, between &lt;code&gt;--env&lt;/code&gt; and the server name.&lt;/p&gt;

&lt;p&gt;Claude Code sets &lt;code&gt;CLAUDE_PROJECT_DIR&lt;/code&gt; in the spawned server's environment. If you reference that variable with &lt;code&gt;${VAR}&lt;/code&gt; expansion in a project &lt;code&gt;.mcp.json&lt;/code&gt; or in a local- or user-scoped entry in &lt;code&gt;~/.claude.json&lt;/code&gt;, you need a default such as &lt;code&gt;${CLAUDE_PROJECT_DIR:-.}&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Choosing a scope
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Current project, private to you (default)&lt;/span&gt;
claude mcp add --transport http stripe https://mcp.stripe.com

&lt;span class="c"&gt;# Write a shared .mcp.json for the team&lt;/span&gt;
claude mcp add --transport http shared-server --scope project https://example.com/mcp

&lt;span class="c"&gt;# Available in all of your projects&lt;/span&gt;
claude mcp add --transport http hubspot --scope user https://mcp.hubspot.com/anthropic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the same server name exists in more than one scope, Claude Code does not merge the entries. It uses the entire definition from the highest-precedence source. Precedence is local, then project, then user.&lt;/p&gt;

&lt;p&gt;Project-scoped servers from &lt;code&gt;.mcp.json&lt;/code&gt; require approval in an interactive session. To reset those choices, run &lt;code&gt;claude mcp reset-project-choices&lt;/code&gt;. In a freshly cloned repository, approvals committed in the repo may not apply until you trust the workspace.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do not hardcode secrets in &lt;code&gt;.mcp.json&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;In a shared &lt;code&gt;.mcp.json&lt;/code&gt;, reference environment variables instead of writing the token itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"api-server"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"http"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"${API_BASE_URL:-https://api.example.com}/mcp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"headers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Bearer ${API_KEY}"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;${VAR}&lt;/code&gt; expands to the value of &lt;code&gt;VAR&lt;/code&gt;. &lt;code&gt;${VAR:-default}&lt;/code&gt; uses &lt;code&gt;default&lt;/code&gt; when &lt;code&gt;VAR&lt;/code&gt; is unset. A variable set to an empty string counts as set, so the default is not used.&lt;/p&gt;

&lt;p&gt;One more caveat: in a remote server's &lt;code&gt;url&lt;/code&gt; or &lt;code&gt;headers&lt;/code&gt;, Claude Code leaves certain credential variable names empty instead of expanding them. That includes names such as &lt;code&gt;ANTHROPIC_API_KEY&lt;/code&gt;, &lt;code&gt;AWS_BEARER_TOKEN_BEDROCK&lt;/code&gt;, and &lt;code&gt;NPM_TOKEN&lt;/code&gt;. Copy the value into a variable with a name of your own, then reference that name.&lt;/p&gt;

&lt;p&gt;If you are adapting an &lt;code&gt;mcpServers&lt;/code&gt; block written for another client, pass &lt;code&gt;claude mcp add-json &amp;lt;name&amp;gt; '&amp;lt;the inner object&amp;gt;'&lt;/code&gt; the object inside &lt;code&gt;mcpServers&lt;/code&gt;, not the wrapper.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding a server in Codex CLI
&lt;/h2&gt;

&lt;p&gt;Codex stores MCP configuration in &lt;code&gt;config.toml&lt;/code&gt;. The default is the user-level file &lt;code&gt;~/.codex/config.toml&lt;/code&gt;. You can also scope servers to a trusted project with &lt;code&gt;.codex/config.toml&lt;/code&gt;. The ChatGPT desktop app, Codex CLI, and the IDE extension share this host configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding a server with the CLI
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# stdio&lt;/span&gt;
codex mcp add &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;server-name&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --env &lt;span class="nv"&gt;VAR1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;VALUE1 --env &lt;span class="nv"&gt;VAR2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;VALUE2 -- &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;stdio server-command&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;# Example&lt;/span&gt;
codex mcp add context7 -- npx -y @upstash/context7-mcp

&lt;span class="c"&gt;# Remote HTTP, with an OAuth client ID&lt;/span&gt;
codex mcp add example --url https://mcp.example.com --oauth-client-id my-client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a server that supports OAuth, run &lt;code&gt;codex mcp login &amp;lt;server-name&amp;gt;&lt;/code&gt;. In a terminal without a local browser, use &lt;code&gt;codex mcp login &amp;lt;server-name&amp;gt; --no-browser&lt;/code&gt;, open the printed authorization URL, and paste the full redirect URL back into the terminal. OAuth login is for Streamable HTTP servers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing &lt;code&gt;config.toml&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;A stdio example, forwarding a token from the environment instead of hardcoding it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="k"&gt;[mcp_servers.context7]&lt;/span&gt;
&lt;span class="na"&gt;command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"npx"&lt;/span&gt;
&lt;span class="na"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"-y"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"@upstash/context7-mcp"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="na"&gt;env_vars&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"LOCAL_TOKEN"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;[mcp_servers.context7.env]&lt;/span&gt;
&lt;span class="na"&gt;MY_ENV_VAR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"MY_ENV_VALUE"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Streamable HTTP example. The bearer token is specified by environment variable name, not by the value itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="k"&gt;[mcp_servers.figma]&lt;/span&gt;
&lt;span class="na"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://mcp.figma.com/mcp"&lt;/span&gt;
&lt;span class="na"&gt;bearer_token_env_var&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"FIGMA_OAUTH_TOKEN"&lt;/span&gt;
&lt;span class="na"&gt;http_headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"X-Figma-Region"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"us-east-1"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fields I use most often are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;stdio: &lt;code&gt;command&lt;/code&gt; (required), &lt;code&gt;args&lt;/code&gt;, &lt;code&gt;env&lt;/code&gt;, &lt;code&gt;env_vars&lt;/code&gt;, &lt;code&gt;cwd&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;HTTP: &lt;code&gt;url&lt;/code&gt; (required), &lt;code&gt;bearer_token_env_var&lt;/code&gt;, &lt;code&gt;http_headers&lt;/code&gt;, &lt;code&gt;env_http_headers&lt;/code&gt;, &lt;code&gt;auth&lt;/code&gt; (&lt;code&gt;oauth&lt;/code&gt; is the default)&lt;/li&gt;
&lt;li&gt;Optional for either: &lt;code&gt;enabled&lt;/code&gt;, &lt;code&gt;startup_timeout_sec&lt;/code&gt; (default 10 seconds), &lt;code&gt;tool_timeout_sec&lt;/code&gt;, &lt;code&gt;enabled_tools&lt;/code&gt;, &lt;code&gt;disabled_tools&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you pass an OAuth client secret to &lt;code&gt;codex mcp add&lt;/code&gt;, Codex saves it as &lt;code&gt;mcp_servers.&amp;lt;name&amp;gt;.oauth.client_secret&lt;/code&gt; in &lt;code&gt;config.toml&lt;/code&gt;. Keep that file private and out of version control.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding a server in Cursor
&lt;/h2&gt;

&lt;p&gt;In Cursor, you can add a server from the Customize page or by writing &lt;code&gt;mcp.json&lt;/code&gt;. Cursor supports stdio, SSE, and Streamable HTTP. Remote servers can also use OAuth.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Location&lt;/th&gt;
&lt;th&gt;Use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;.cursor/mcp.json&lt;/code&gt; in the project&lt;/td&gt;
&lt;td&gt;Project-specific. Commit it if you want teammates to get the same servers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;~/.cursor/mcp.json&lt;/code&gt; in your home directory&lt;/td&gt;
&lt;td&gt;Available in every project you open in the editor or CLI&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The two files are merged. If the same server name appears in both, the project entry wins. Hosted Cloud Agents do not read &lt;code&gt;~/.cursor/mcp.json&lt;/code&gt; on your machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  stdio and remote examples
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"server-name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"npx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"args"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"-y"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"mcp-server"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"API_KEY"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"${env:API_KEY}"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"server-name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://mcp.example.com/mcp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"headers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Bearer ${env:MY_SERVICE_TOKEN}"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cursor expands variables in &lt;code&gt;command&lt;/code&gt;, &lt;code&gt;args&lt;/code&gt;, &lt;code&gt;env&lt;/code&gt;, &lt;code&gt;url&lt;/code&gt;, and &lt;code&gt;headers&lt;/code&gt;, including &lt;code&gt;${env:NAME}&lt;/code&gt;. Keep secrets out of the file and read them from your shell or system environment. &lt;code&gt;envFile&lt;/code&gt; is available only for stdio servers, not for remote HTTP or SSE servers.&lt;/p&gt;

&lt;p&gt;After you save the file, restart Cursor. The official docs also recommend environment variables for secrets, least privilege for keys, and local stdio for sensitive servers.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to check that a server is connected
&lt;/h2&gt;

&lt;p&gt;Adding a server does not by itself mean it connected. Check the status in each client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Claude Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude mcp list
claude mcp get notion
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside a session, you can also run &lt;code&gt;/mcp&lt;/code&gt;. An &lt;code&gt;Added ...&lt;/code&gt; line from &lt;code&gt;claude mcp add&lt;/code&gt; only means the configuration was written. Use the status afterwards to see whether the server actually connected.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;claude mcp list&lt;/code&gt; reports connection results such as &lt;code&gt;✔ Connected&lt;/code&gt;, &lt;code&gt;! Needs authentication&lt;/code&gt;, or &lt;code&gt;✘ Failed to connect&lt;/code&gt;. These other statuses describe a configuration state, not a connection attempt:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;⏸ Pending approval (run claude to approve)&lt;/code&gt;: a project-scoped server from &lt;code&gt;.mcp.json&lt;/code&gt; that you have not approved yet&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;⊘ Disabled for this project (re-enable via /mcp)&lt;/code&gt;: disabled for this project; you can turn it back on from &lt;code&gt;/mcp&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;✘ Rejected&lt;/code&gt; or a policy block: refused by settings or by an organization policy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you see &lt;code&gt;⏸ Pending approval&lt;/code&gt;, start &lt;code&gt;claude&lt;/code&gt; interactively in that project and accept workspace trust and the server approval. If a remote server needs authentication, complete OAuth from &lt;code&gt;/mcp&lt;/code&gt; or with &lt;code&gt;claude mcp login &amp;lt;name&amp;gt;&lt;/code&gt;. Use &lt;code&gt;claude mcp login &amp;lt;name&amp;gt; --no-browser&lt;/code&gt; when no local browser is available.&lt;/p&gt;

&lt;p&gt;If you want the authorization server to revoke tokens before you delete the server, run &lt;code&gt;claude mcp logout &amp;lt;name&amp;gt;&lt;/code&gt; first. &lt;code&gt;claude mcp remove&lt;/code&gt; deletes the tokens Claude Code stored; it does not revoke them at the issuer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Codex CLI&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;codex mcp list
codex mcp --help
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the TUI, &lt;code&gt;/mcp&lt;/code&gt; shows the servers that are active. After &lt;code&gt;codex mcp login &amp;lt;server-name&amp;gt;&lt;/code&gt; for an OAuth server, check the list again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cursor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Restart Cursor after you save the configuration. The Customize page shows whether a server is enabled and whether it needs an OAuth sign-in. You can also toggle a server off temporarily there. If a connection fails, open the Output panel, choose "MCP Logs", and look for connection errors, authentication failures, or server crashes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pitfalls
&lt;/h2&gt;

&lt;p&gt;These are the mismatches I watch for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The server is configured but does not connect&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Claude Code &lt;code&gt;.mcp.json&lt;/code&gt; entry has a &lt;code&gt;url&lt;/code&gt; but no &lt;code&gt;type&lt;/code&gt;, so it is read as a stdio server and fails&lt;/li&gt;
&lt;li&gt;A project-scoped server is still pending approval (&lt;code&gt;⏸ Pending approval&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;You saved Cursor's &lt;code&gt;mcp.json&lt;/code&gt; but have not restarted Cursor&lt;/li&gt;
&lt;li&gt;The command that starts a stdio server (&lt;code&gt;npx&lt;/code&gt; or &lt;code&gt;python&lt;/code&gt;) is not on the PATH in that environment&lt;/li&gt;
&lt;li&gt;You set an environment variable only in the current session, so the agent or another window cannot see it. In Windows PowerShell, &lt;code&gt;$Env:API_KEY = "YOUR_KEY"&lt;/code&gt; lasts only for the current process&lt;/li&gt;
&lt;li&gt;A Claude Code remote entry references a reserved credential variable such as &lt;code&gt;${ANTHROPIC_API_KEY}&lt;/code&gt;, which is expanded to empty&lt;/li&gt;
&lt;li&gt;The same server name exists in more than one scope, and a definition you did not intend is the one that loads. Claude Code warns about the conflict in &lt;code&gt;claude mcp list&lt;/code&gt; and &lt;code&gt;/mcp&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How you pass a key&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Do not commit the key itself in a shared config file. Use &lt;code&gt;${API_KEY}&lt;/code&gt; in Claude Code's &lt;code&gt;.mcp.json&lt;/code&gt;, &lt;code&gt;${env:API_KEY}&lt;/code&gt; in Cursor, and &lt;code&gt;bearer_token_env_var&lt;/code&gt; or &lt;code&gt;env_vars&lt;/code&gt; in Codex, and keep the value in the environment. Putting the value on the command line can leave it in shell history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows-specific friction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Much of the official documentation uses bash examples. In PowerShell, use &lt;code&gt;$Env:API_KEY = "..."&lt;/code&gt; instead of &lt;code&gt;export API_KEY=...&lt;/code&gt;. A session-only variable is a common reason Claude Code or Cursor, started from another terminal, cannot see the key.&lt;/p&gt;

&lt;p&gt;Home-directory config files (&lt;code&gt;~/.claude.json&lt;/code&gt;, &lt;code&gt;~/.codex/config.toml&lt;/code&gt;, &lt;code&gt;~/.cursor/mcp.json&lt;/code&gt;) live under your user profile on Windows. If you type a path by hand, check the home directory of the environment you are actually using.&lt;/p&gt;

&lt;p&gt;A stdio MCP server is started directly by the host. If &lt;code&gt;npx&lt;/code&gt; works in your terminal but the server fails to start, look at the PATH the agent process sees. That part varies by environment, so I rely on each client's logs: &lt;code&gt;/mcp&lt;/code&gt; or &lt;code&gt;claude mcp get&lt;/code&gt; in Claude Code, MCP Logs in Cursor, and &lt;code&gt;codex mcp list&lt;/code&gt; in Codex.&lt;/p&gt;

&lt;h2&gt;
  
  
  Official documentation I used
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://modelcontextprotocol.io/docs/learn/architecture" rel="noopener noreferrer"&gt;MCP Architecture overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization" rel="noopener noreferrer"&gt;MCP Authorization&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://code.claude.com/docs/en/mcp" rel="noopener noreferrer"&gt;Connect Claude Code to tools via MCP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.chatgpt.com/docs/extend/mcp" rel="noopener noreferrer"&gt;Codex: Model Context Protocol&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.chatgpt.com/docs/config-file/config-reference" rel="noopener noreferrer"&gt;Codex configuration reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cursor.com/docs/mcp" rel="noopener noreferrer"&gt;Cursor: Model Context Protocol (MCP)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Closing
&lt;/h2&gt;

&lt;p&gt;When I connect an MCP server, I check three things: the transport (stdio or HTTP), the scope (this project or every project), and whether the client actually reports a successful connection. On Windows, using Claude Code, Codex, and Cursor side by side, the easy mistake is mixing up config-file locations and the environment in which a variable is visible. I look at those first.&lt;/p&gt;

&lt;p&gt;If a step is wrong or the docs have changed, follow the official documentation.&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>AI Agents Are Shifting from Something You Build to Something You Delegate</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Sun, 22 Nov 2026 07:25:42 +0000</pubDate>
      <link>https://dev.to/koheip/ai-agents-are-shifting-from-something-you-build-to-something-you-delegate-4n95</link>
      <guid>https://dev.to/koheip/ai-agents-are-shifting-from-something-you-build-to-something-you-delegate-4n95</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I'm a second-year student at ZEN University studying intelligent informatics, and I want to become an AI engineer. I build AI agents as personal projects.&lt;/p&gt;

&lt;p&gt;The conversation around AI agents has shifted, at least in my daily work. For a while, the center of the discussion was how to &lt;em&gt;build&lt;/em&gt; an agent. What I see now in ordinary development is how to &lt;em&gt;delegate&lt;/em&gt; work to one. It feels as if we have moved from an era of agent development to an era of handing work to agents and letting them carry it out.&lt;/p&gt;

&lt;p&gt;The skill that matters from here is not only the ability to build an agent. It is also the ability to design how work is delegated. In this article I gather what I think is needed when you hand work to an agent, drawing on two experiences: building an agent myself, and delegating implementation, tests, research, and documentation to Claude Code and Codex every day.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the conversation was about building
&lt;/h2&gt;

&lt;p&gt;Until recently, talk about AI agents was mostly about how to build them. Which model to use, how to wire tools, how to design RAG and memory. Those topics still matter.&lt;/p&gt;

&lt;p&gt;I also built a personal AI agent, Yata, and experienced both the interest and the difficulty of making one. Yata is a personal assistant that runs on my own PC. You talk to it in Japanese in a chat, and it helps with research and with checking mail and calendars. While building it, I had to think not only about model choice, but also about how tools are connected, and about asking a person to confirm before any action that leaves the machine.&lt;/p&gt;

&lt;p&gt;The code and write-ups are here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/koheip/yata" rel="noopener noreferrer"&gt;https://github.com/koheip/yata&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Qiita (Japanese): &lt;a href="https://qiita.com/koheip/items/5ff8f86d8594822162a5" rel="noopener noreferrer"&gt;https://qiita.com/koheip/items/5ff8f86d8594822162a5&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Zenn (Japanese): &lt;a href="https://zenn.dev/koheip/articles/yata-local-ai-assistant" rel="noopener noreferrer"&gt;https://zenn.dev/koheip/articles/yata-local-ai-assistant&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;DEV: &lt;a href="https://dev.to/koheip/i-built-yata-a-local-first-personal-ai-assistant-for-everyday-work-in-japan-2noi"&gt;https://dev.to/koheip/i-built-yata-a-local-first-personal-ai-assistant-for-everyday-work-in-japan-2noi&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What has changed in daily development
&lt;/h2&gt;

&lt;p&gt;The way I develop day to day has been changing. I use Claude Code and Codex every day, and I hand much of the implementation, testing, research, and documentation to the agents.&lt;/p&gt;

&lt;p&gt;My role has been moving from "the person who writes the code" toward "the person who decides what to hand over, and then checks the result." That does not mean I have stopped writing code. Writing and delegating-and-verifying now sit side by side in the same work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Four things that matter when you delegate
&lt;/h2&gt;

&lt;p&gt;These are the four things I find necessary in a time of delegation. They are not a special method. They are items that are less likely to go wrong if you decide them before you hand a task to Claude Code or Codex. I describe them as general practice. I will not invent numbers about how much faster any particular job became.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Splitting the task: write the goal and the done conditions first
&lt;/h3&gt;

&lt;p&gt;If you only tell an agent to "handle it well," the scope often grows, or the agent starts "improving" things you did not ask for. Split the work into a size the agent can finish in one pass, and state the goal and the done conditions up front.&lt;/p&gt;

&lt;p&gt;The way I try to write this looks like the following.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;State the goal in one sentence.&lt;/strong&gt; For example: "Add email and password validation to the login screen."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;List the done conditions.&lt;/strong&gt; For example: existing tests pass, new tests are added, files outside the requested area are not changed, the API shape does not change.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Also write what not to do.&lt;/strong&gt; For example: do not redesign the UI, do not update dependencies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Split requests that are too large.&lt;/strong&gt; Instead of "make this feature better," use "add tests first," then "fix the implementation," then "update the docs."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When the done conditions are written down, the agent and I can judge "is this finished?" against the same bar. If you move on while that is still vague, you end up coming back later.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. How you pass context: premises, constraints, and what not to touch
&lt;/h3&gt;

&lt;p&gt;An agent may be able to read part of a repository, but it does not know the premises that live only in your head. If you do not say them first, it may rewrite code in a style you do not use, or edit files that should not be touched.&lt;/p&gt;

&lt;p&gt;Information worth passing first includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Premises:&lt;/strong&gt; what the project is, which language or framework it uses, and what is going wrong right now&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Constraints:&lt;/strong&gt; do not change the public API, match the style of this file, ask before adding a new dependency&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What not to touch:&lt;/strong&gt; &lt;code&gt;.env&lt;/code&gt; and other secrets, production configuration, unrelated directories, generated files, and lockfiles that should not be rewritten without a reason&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A simple approach with Claude Code or Codex is to say, explicitly, "Do not change the following paths." Write concrete paths for files that contain secrets, deploy configuration, and directories managed by someone else. It also helps to name the directories that &lt;em&gt;may&lt;/em&gt; be changed, so the scope of the diff is easier to follow later.&lt;/p&gt;

&lt;p&gt;You do not have to pass everything at once. The premises needed for that task, and the lines that must not be crossed, are often enough.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Verification: check the result with tests, review, and evaluation
&lt;/h3&gt;

&lt;p&gt;After you delegate, you still need to check what came back. An agent may say the tests passed, but the tests may cover very little. I do not take the result as ready to merge without a review.&lt;/p&gt;

&lt;p&gt;The points I look at are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Tests:&lt;/strong&gt; are there new tests, were existing tests run, and did the change hide a failure&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Review:&lt;/strong&gt; is there a diff outside the requested scope, an unasked-for refactor or new dependency, or a secret mixed into the change&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Evaluation:&lt;/strong&gt; are the done conditions met? If not, write what is missing into the next request&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can ask the agent to run the tests and report the result. I still read the diff myself, and I run things locally when I need to, rather than taking the report as final. Verification is not the opposite of delegation. It is part of delegating.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Permissions and safety: what may run automatically, and what needs a person
&lt;/h3&gt;

&lt;p&gt;The more you let an agent into a repository or let it run commands, the more important the boundary becomes. If everything is manual, it is hard to delegate. If everything is automatic, operations you cannot undo may run.&lt;/p&gt;

&lt;p&gt;One way to draw the line is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Often fine to do automatically:&lt;/strong&gt; reading code, running tests, producing a proposed diff, editing on a working branch&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Needs a person's confirmation:&lt;/strong&gt; a forced git overwrite, deleting files or branches, changing secrets or production configuration, deploying to production, publishing (a package or an article), and adding a new dependency with broad permissions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The important point is not to confuse what a tool &lt;em&gt;can&lt;/em&gt; do with what it &lt;em&gt;may&lt;/em&gt; do. If you keep history in git, you can still revert after trying a proposal. Operations that cannot be undone, that leave the machine, or that publish something, stay on the confirmation side.&lt;/p&gt;

&lt;p&gt;When I built Yata, I used the same idea: wait for a person to confirm before actions that leave the machine, such as sending mail or creating a calendar event. The same thinking applies when you are the one delegating. The more you let an agent carry out work for you, the more you need to decide in advance where it must stop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Experience building, and experience delegating
&lt;/h2&gt;

&lt;p&gt;These four items can look like a discussion of process. I still feel that I can delegate more carefully because I have built the inside of an agent.&lt;/p&gt;

&lt;p&gt;A model does not always follow instructions. Tools fail. Context runs short. If permissions are broad, unintended actions can run. Having seen that from the building side makes it easier to translate "where to stop," "what to say first," and "what counts as done" into the language of delegation.&lt;/p&gt;

&lt;p&gt;I think both experiences — building and delegating — will be a strength for AI engineers. Not one or the other. If you can build, you can design how to delegate. If you try delegating, you can see what is worth building next. I am moving back and forth between the two.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing
&lt;/h2&gt;

&lt;p&gt;I feel the center of gravity of AI agents is moving from something you build to something you delegate work to. That does not mean the building conversation is over. In everyday development, though, handing implementation, tests, research, and documentation to Claude Code or Codex is already a normal option.&lt;/p&gt;

&lt;p&gt;The four things I try to get right when I delegate are splitting the task, passing context, verifying the result, and drawing the line on permissions and safety. They are less a clever trick than a plain habit: decide first, and write it down.&lt;/p&gt;

&lt;p&gt;I study intelligent informatics at ZEN University, and I keep doing both: building AI myself, and handing development work to AI. I would be glad to exchange notes with others who are also trying out this way of working with agents.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>I Built Yata, a Local-First Personal AI Assistant for Everyday Work in Japan</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Sat, 21 Nov 2026 15:46:03 +0000</pubDate>
      <link>https://dev.to/koheip/i-built-yata-a-local-first-personal-ai-assistant-for-everyday-work-in-japan-2noi</link>
      <guid>https://dev.to/koheip/i-built-yata-a-local-first-personal-ai-assistant-for-everyday-work-in-japan-2noi</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I'm a second-year student at ZEN University studying intelligent informatics, and I want to become an AI engineer. I build AI agents as personal projects. I have no professional work experience as an engineer.&lt;/p&gt;

&lt;p&gt;Yata (ヤタ) is a personal AI assistant that runs on your own computer. You talk to it in chat, in Japanese by default, and it can search the web, read pages, check mail and calendars, run scheduled jobs, and connect to services people often use in Japan. Conversations and memory stay in SQLite on the PC, not in a cloud of my own.&lt;/p&gt;

&lt;p&gt;Up front: this is a &lt;strong&gt;beta&lt;/strong&gt;. The README says it is early, and some things may not work well. This article is a record of the design so far, not a claim that the product is finished.&lt;/p&gt;

&lt;p&gt;The code is MIT-licensed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/koheip/yata" rel="noopener noreferrer"&gt;https://github.com/koheip/yata&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Site: &lt;a href="https://koheip.github.io/yata/" rel="noopener noreferrer"&gt;https://koheip.github.io/yata/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why I built it
&lt;/h2&gt;

&lt;p&gt;I wanted something in the same class as Grok Bot: an assistant that runs on my own PC, looks things up, acts only when it needs to, and stops before anything risky.&lt;/p&gt;

&lt;p&gt;There are already many chat apps. The reasons to build my own were:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Keep data local.&lt;/strong&gt; History and a few long-term facts live on the user's PC from the start.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Japanese first, including services people actually use in Japan.&lt;/strong&gt; Not only Gmail and Google Calendar, but LINE, Chatwork, Backlog, kintone, freee, Money Forward Invoice, and Rakuten Ichiba.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ask before anything leaves the machine.&lt;/strong&gt; Sending mail or creating an event should never happen just because the model decided to.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The name comes from Yatagarasu (八咫烏), the sacred three-legged crow that, in tradition, guided Emperor Jimmu. The role I wanted was a guide that shows the way. The mascot is a round purple baby crow; I gave it two legs, because I wanted it to feel friendly rather than strictly mythological.&lt;/p&gt;

&lt;p&gt;The first commits used the name 灯 (Tomoshibi, "lamp"). I renamed it to Yata on the same day, once the "guide" image felt right.&lt;/p&gt;

&lt;p&gt;I also wanted one project that I could use every day while studying, show as a portfolio piece, and later hand to other people. This is the first version that tries to do all three.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I built it
&lt;/h2&gt;

&lt;p&gt;I started Yata in Grok Bot and finished it with Claude. I gave instructions and wrote the code by talking with those tools. I don't have a clean record of which parts each one wrote, or of why I switched, so I won't invent one. The public repository is the result of that process.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it can do
&lt;/h2&gt;

&lt;p&gt;These are the capabilities described in the README:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Research:&lt;/strong&gt; web search through DuckDuckGo (&lt;code&gt;ddgs&lt;/code&gt;, no API key), then fetch a page and extract the main text&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mail and calendar:&lt;/strong&gt; search, read, and draft Gmail; list events and check free/busy on Google Calendar. Sending mail and creating, updating, or deleting events wait for confirmation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chat from LINE:&lt;/strong&gt; you can message Yata from the LINE app. Risky actions show Allow / Deny buttons&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connectors for work in Japan:&lt;/strong&gt; Chatwork messages and tasks, Backlog issues, kintone records, freee, Money Forward Invoice, LINE Official Account broadcasts, and Rakuten Ichiba product search&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Japanese business calculations:&lt;/strong&gt; holidays, business days, the Japanese imperial calendar, and qualified invoice (invoice system) consumption tax. It also writes polite Japanese&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Routines:&lt;/strong&gt; a request like "summarize the news at 8:00 every morning" runs at that time. The result can also be sent to LINE&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory:&lt;/strong&gt; short facts about you are stored and injected into the next system prompt&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser control:&lt;/strong&gt; a headless Chromium page per conversation, via Playwright (open, extract, click, type, screenshot). Clicks and typing wait for confirmation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You choose the model. You can bring one API key for Gemini, OpenAI, Anthropic, xAI (Grok), DeepSeek, Kimi, Mistral, Groq, OpenRouter, or PLaMo, or run a local model through Ollama, LM Studio, llama.cpp, Jan, vLLM, LocalAI, and other OpenAI-compatible servers. Gemini's free tier or a local model can make it free to run. If you have no key, a built-in &lt;code&gt;demo&lt;/code&gt; model still exercises the real loop and the real tools; it is not there to judge answer quality.&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;offline mode&lt;/strong&gt; in settings uses only a local model and disables web search, the browser, external connectors, and LINE notifications, so the conversation does not leave the PC.&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;

&lt;p&gt;The backend is Python 3.11+ and FastAPI, managed with uv. The UI is React, TypeScript, Tailwind CSS, Vite, and shadcn/ui. The agent loop, Playwright, and SQLite live in one process. After &lt;code&gt;npm run build&lt;/code&gt;, FastAPI serves the UI on the same port (default &lt;code&gt;http://127.0.0.1:8741&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TB
  UI["Chat UI&amp;lt;br/&amp;gt;React + TypeScript"]
  API["FastAPI&amp;lt;br/&amp;gt;chat, SSE, confirmations"]
  Loop["Agent loop"]
  Policy["ToolPolicy"]
  Gate["ConfirmationGate"]
  Router["ModelRouter"]
  Registry["ToolRegistry"]
  DB[("SQLite&amp;lt;br/&amp;gt;conversations and facts")]

  UI --&amp;gt;|message| API
  UI --&amp;gt;|allow / deny| Gate
  API --&amp;gt; Loop
  API --&amp;gt; DB
  Loop --&amp;gt; Router
  Loop --&amp;gt; Policy
  Policy --&amp;gt; Gate
  Loop --&amp;gt; Registry&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;One turn is: think, call a tool, observe, think again. The default cap is 8 model calls (&lt;code&gt;YATA_MAX_STEPS&lt;/code&gt;). Intermediate events such as &lt;code&gt;tool_call&lt;/code&gt;, &lt;code&gt;confirmation_required&lt;/code&gt;, &lt;code&gt;tool_result&lt;/code&gt;, and &lt;code&gt;answer&lt;/code&gt; are streamed to the chat as Server-Sent Events.&lt;/p&gt;

&lt;p&gt;The main packages are:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Path&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;src/yata/agent/loop.py&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Think, call a tool, observe, answer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;src/yata/llm/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Provider adapters; vendor translation lives in &lt;code&gt;convert.py&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;src/yata/tools/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Tool interface, registry, and risk&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;src/yata/confirm/gate.py&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Risky actions approved from a separate UI request&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;src/yata/memory/store.py&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;SQLite for conversations and facts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;src/yata/routines/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stored routines and an in-process APScheduler&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;src/yata/connectors/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Auth and connections to outside services&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;src/yata/api/app.py&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;HTTP and SSE; also serves the built UI&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;frontend/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Japanese chat UI&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Design choices
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Tools carry a risk; the loop only asks the policy
&lt;/h3&gt;

&lt;p&gt;A tool is a class with a name, a JSON schema, a &lt;code&gt;Risk&lt;/code&gt;, and &lt;code&gt;run()&lt;/code&gt;. Adding one is a single registration in &lt;code&gt;tools/catalog.py&lt;/code&gt;. There are four risks:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Risk&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Default&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;read&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Search, page fetch, screenshots, reading Gmail or the calendar&lt;/td&gt;
&lt;td&gt;Run immediately&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;write&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Local memory, creating a Gmail draft&lt;/td&gt;
&lt;td&gt;Run immediately&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mutate&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Browser click and type&lt;/td&gt;
&lt;td&gt;Confirm first&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;external&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sending mail, creating or changing events, sending messages, recording expenses, and so on&lt;/td&gt;
&lt;td&gt;Confirm first&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The loop does not special-case tools. It asks &lt;code&gt;ToolPolicy&lt;/code&gt; whether confirmation is required:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="no"&gt;CONFIRM_RISKS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Risk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;MUTATE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Risk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;EXTERNAL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ToolPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;needs_confirmation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Tool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;del&lt;/span&gt; &lt;span class="n"&gt;arguments&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;risk&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;CONFIRM_RISKS&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it is, the loop first yields &lt;code&gt;confirmation_required&lt;/code&gt; so the UI can show Allow / Deny, then waits. A denial or a timeout is not treated as approval.&lt;/p&gt;

&lt;p&gt;The gate itself is an in-memory &lt;code&gt;asyncio.Future&lt;/code&gt; that joins the agent loop to a later HTTP request from the UI (or from LINE). Timeouts fall closed: when in doubt, do not run. Because the gate lives in process memory, pending confirmations disappear if the server stops. That is still a rough edge.&lt;/p&gt;

&lt;p&gt;Tools whose connector is not connected are hidden from the model (&lt;code&gt;visible_registry()&lt;/code&gt;). The app still starts if a key is missing; those tools simply do not appear.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Official SDKs instead of a universal wrapper
&lt;/h3&gt;

&lt;p&gt;A single wrapper such as LiteLLM was a real option. In this version I used the official SDKs (&lt;code&gt;google-genai&lt;/code&gt;, &lt;code&gt;openai&lt;/code&gt;, &lt;code&gt;anthropic&lt;/code&gt;). The provider interface is only &lt;code&gt;complete(messages, tools, model)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Vendor differences — especially how tool results are returned (OpenAI &lt;code&gt;tool&lt;/code&gt; messages, Anthropic &lt;code&gt;tool_result&lt;/code&gt; blocks, Gemini &lt;code&gt;function_response&lt;/code&gt; parts) — stay in &lt;code&gt;llm/convert.py&lt;/code&gt;, where they are readable. A wrapper would mean less code and more dependencies, and the conversion would be harder to see. This is a learning project and a portfolio piece, so I chose the seam I can read.&lt;/p&gt;

&lt;p&gt;Ollama, LM Studio, vLLM, and other OpenAI-compatible servers reuse the OpenAI adapter with a different &lt;code&gt;base_url&lt;/code&gt;. Providers without a key show up as unavailable, and the API rejects them before a request is sent.&lt;/p&gt;

&lt;p&gt;For small local models, Yata uses a shorter system prompt (&lt;code&gt;COMPACT_PROMPT&lt;/code&gt;), because a long brief makes it easier for a small model to lose the thread. Browser tools are also withheld from local models by default (&lt;code&gt;YATA_LOCAL_BROWSER_TOOLS&lt;/code&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Keep the public surface small
&lt;/h3&gt;

&lt;p&gt;Page fetching inspects the URL after every redirect. Cloud metadata addresses (&lt;code&gt;169.254.169.254&lt;/code&gt; and &lt;code&gt;metadata.google.internal&lt;/code&gt;) are always blocked. Private hosts are controlled by &lt;code&gt;YATA_ALLOW_PRIVATE_URLS&lt;/code&gt; (the personal default is &lt;code&gt;true&lt;/code&gt;; turn it off before a public deploy).&lt;/p&gt;

&lt;p&gt;The LINE webhook is a separate server on &lt;code&gt;127.0.0.1:8742&lt;/code&gt; that exposes only &lt;code&gt;/line/webhook&lt;/code&gt; and &lt;code&gt;/line/health&lt;/code&gt;. Incoming events are limited by signature verification and an allowlist of user IDs. The tunnel publishes this webhook only. The main UI on port 8741 is not exposed.&lt;/p&gt;

&lt;p&gt;cloudflared quick-tunnel URLs change on every start. Yata starts the tunnel itself and re-registers the webhook URL with LINE when it changes. You can turn that off with &lt;code&gt;YATA_LINE_TUNNEL=false&lt;/code&gt; and run a tunnel by hand.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Routines run in the same process
&lt;/h3&gt;

&lt;p&gt;If you type "summarize the news at 8:00 every morning," or add a routine from the sidebar, APScheduler in the same process calls the same agent loop. The default timezone is &lt;code&gt;Asia/Tokyo&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can close the browser tab. As long as the Yata process is still running, the job runs and the result is stored in that routine's conversation. Risky tools do not run unattended; they wait for confirmation until you open the app. If you turn on LINE notification for a routine, that notification is treated as something you already configured, so it is sent without a per-run confirmation.&lt;/p&gt;

&lt;p&gt;There is not yet a Windows service or an OS notification. The process has to stay up. That is later on the roadmap.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was hard, and what is still rough
&lt;/h2&gt;

&lt;p&gt;The hardest part was not the agent loop. It was the first-time setup. Gmail and Calendar need a Google Cloud project, enabled APIs, an OAuth consent screen, a desktop-app client, and your account as a test user. LINE needs an Official Account, the Messaging API, allowed user IDs, and a tunnel. The more connectors I added, the longer the path became before I could use the app myself.&lt;/p&gt;

&lt;p&gt;Other beta limits I want to be clear about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pending confirmations live in memory, so a restart drops them&lt;/li&gt;
&lt;li&gt;Browser login state does not survive a restart (one headless page per conversation)&lt;/li&gt;
&lt;li&gt;Routines only run while the Yata process is up&lt;/li&gt;
&lt;li&gt;OS-level desktop control (moving the real mouse, and so on) is not implemented&lt;/li&gt;
&lt;li&gt;The README has placeholders for screenshots and a demo GIF, but those files are not in the repo yet&lt;/li&gt;
&lt;li&gt;The Microsoft Store listing is still marked as in preparation. GitHub Releases has v0.1.0 as &lt;code&gt;Yata-Setup-0.1.0.exe&lt;/code&gt; and an MSIX. The Setup.exe is unsigned, so Windows may show "Windows protected your PC" until you choose More info → Run anyway&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tests run with &lt;code&gt;uv run pytest&lt;/code&gt; and do not use the network or real API keys. They cover the agent loop, confirmations, provider conversion, memory, routines, and connectors, using mocks.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to run it (Windows)
&lt;/h2&gt;

&lt;p&gt;If you have &lt;a href="https://docs.astral.sh/uv/" rel="noopener noreferrer"&gt;uv&lt;/a&gt;, Node.js (the README says around 22), and Git, this PowerShell line is enough. The script tells you what is missing; it does not install tools on its own.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;git&lt;/span&gt; &lt;span class="n"&gt;clone&lt;/span&gt; &lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;github&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;koheip&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;yata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;git&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;cd&lt;/span&gt; &lt;span class="n"&gt;yata&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;powershell&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ExecutionPolicy&lt;/span&gt; &lt;span class="nc"&gt;Bypass&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;File&lt;/span&gt; &lt;span class="n"&gt;scripts&lt;/span&gt;\&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then start it with &lt;code&gt;uv run yata&lt;/code&gt;. The first launch walks you through connecting an AI. If the app window does not open, visit &lt;a href="http://127.0.0.1:8741" rel="noopener noreferrer"&gt;http://127.0.0.1:8741&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For development, &lt;code&gt;./scripts/run.sh&lt;/code&gt; also works. Browser tools need &lt;code&gt;uv run playwright install chromium&lt;/code&gt;. Search, reading, and memory work without it.&lt;/p&gt;

&lt;p&gt;The installer is on &lt;a href="https://github.com/koheip/yata/releases" rel="noopener noreferrer"&gt;Releases&lt;/a&gt;. App data for the packaged build lives under &lt;code&gt;%LOCALAPPDATA%\Yata&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is next
&lt;/h2&gt;

&lt;p&gt;The roadmap treats the foundation (the loop, tools, the confirmation gate, and memory), in-process routines, and connectors including Gmail and Calendar as done. Later phases describe a desktop wrapper with a tray, auto-start, and OS notifications, and a hosted version whose routines would keep running when the PC is off. I am not treating planned work as if it already exists.&lt;/p&gt;

&lt;p&gt;I want to use it every day, reduce setup friction, and fix the rough edges. Bug reports and ideas are welcome in GitHub Issues.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/koheip/yata" rel="noopener noreferrer"&gt;https://github.com/koheip/yata&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Site: &lt;a href="https://koheip.github.io/yata/" rel="noopener noreferrer"&gt;https://koheip.github.io/yata/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Latest release: &lt;a href="https://github.com/koheip/yata/releases/tag/v0.1.0" rel="noopener noreferrer"&gt;https://github.com/koheip/yata/releases/tag/v0.1.0&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>fastapi</category>
      <category>llm</category>
      <category>typescript</category>
    </item>
    <item>
      <title>I Built a Tiny Japanese GPT from Scratch in PyTorch and Tried a Toy 'RSI' Loop: Here's What It Does and Doesn't Show</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Fri, 20 Nov 2026 12:34:26 +0000</pubDate>
      <link>https://dev.to/koheip/i-built-a-tiny-japanese-gpt-from-scratch-in-pytorch-and-tried-a-toy-rsi-loop-heres-what-it-does-415j</link>
      <guid>https://dev.to/koheip/i-built-a-tiny-japanese-gpt-from-scratch-in-pytorch-and-tried-a-toy-rsi-loop-heres-what-it-does-415j</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I'm a second-year student at ZEN University studying intelligent informatics (online), and I build AI agents as a personal project. I have no work experience in machine learning.&lt;/p&gt;

&lt;p&gt;I use LLMs through APIs and agents every day, but I wanted to see what happens inside one with my own hands. So I wrote a small Japanese GPT using only basic PyTorch operations: no pretrained weights, no high-level model libraries. Then I tried a toy version of "RSI" (recursive self-improvement): the model generates several answers, grades them itself, and retrains on the best ones.&lt;/p&gt;

&lt;p&gt;Up front: this is a &lt;strong&gt;tiny educational model trained on a few KB of text&lt;/strong&gt;. Don't expect it to be useful, and please don't read the RSI numbers as "the model got smarter." I'll explain why below. This is not AGI or anything close to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I built
&lt;/h2&gt;

&lt;p&gt;A character-level, decoder-only Transformer with about 0.9M parameters (the pretraining version has 898,425, which I also checked by hand from the layer sizes). It has three stages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;mini_gpt.py&lt;/code&gt;: character tokenizer + Transformer, pretrained on short excerpts of modern Japanese literature to continue text.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;chat_gpt.py&lt;/code&gt;: the same architecture, fine-tuned on &lt;code&gt;ユーザー: ...\nAI: ...◁&lt;/code&gt; dialogues so it behaves like a chatbot.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rsi_gpt.py&lt;/code&gt;: a best-of-N self-training loop.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There is also a local web UI (&lt;code&gt;web_ui.py&lt;/code&gt;, standard-library &lt;code&gt;http.server&lt;/code&gt; only) that shows the top-5 probabilities for the first generated character and lets you edit the dialogue data and retrain in the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. A minimal Transformer
&lt;/h3&gt;

&lt;p&gt;Hyperparameters in &lt;code&gt;mini_gpt.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="no"&gt;BLOCK_SIZE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;64&lt;/span&gt;       &lt;span class="c1"&gt;# max context length&lt;/span&gt;
&lt;span class="no"&gt;N_EMBD&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;128&lt;/span&gt;          &lt;span class="c1"&gt;# embedding dimension&lt;/span&gt;
&lt;span class="no"&gt;N_HEAD&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;            &lt;span class="c1"&gt;# attention heads&lt;/span&gt;
&lt;span class="no"&gt;N_LAYER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;           &lt;span class="c1"&gt;# Transformer blocks&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Causal self-attention masks out future characters with a lower-triangular mask before the softmax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;att&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt; @ &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transpose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;head_dim&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;att&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;att&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;masked_fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mask&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"-inf"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;att&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;F&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;softmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;att&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dim&lt;/span&gt;&lt;span class="o"&gt;=-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each block is Pre-LayerNorm with two residual connections:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;forward&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;attn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ln1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# residual + attention&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mlp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ln2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# residual + feed-forward&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tokenizer just numbers the characters that appear in the training text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;chars&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;stoi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ch&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chars&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Turning it into a chatbot
&lt;/h3&gt;

&lt;p&gt;I didn't change the architecture. Two things changed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The input is formatted as &lt;code&gt;"ユーザー: {question}\nAI: "&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Every AI answer in the training data ends with a stop character &lt;code&gt;◁&lt;/code&gt;, and generation stops when it is sampled.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;token_id&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;stop_token_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;  &lt;span class="c1"&gt;# stop when the end marker appears&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without the stop character the model keeps writing the next &lt;code&gt;ユーザー: ...&lt;/code&gt; turn by itself. I call that role leakage below.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. The RSI loop
&lt;/h3&gt;

&lt;p&gt;This is a small-scale best-of-N rejection sampling loop, in the spirit of STaR / ReST:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For each of 7 prompts, generate N=6 candidate answers.&lt;/li&gt;
&lt;li&gt;Score each one out of 100 with a rule-based function.&lt;/li&gt;
&lt;li&gt;If the best candidate scores 75 or more, keep that (prompt, answer) pair as synthetic data.&lt;/li&gt;
&lt;li&gt;Add the synthetic data to the dialogue data and retrain for 350 steps. Repeat for 3 generations.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The score is the sum of four parts (&lt;code&gt;evaluate_candidate&lt;/code&gt;):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Part&lt;/th&gt;
&lt;th&gt;Points&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Completion&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;ended naturally with &lt;code&gt;◁&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Format&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;no "ユーザー"/"AI:" leakage, no newline, no 4+ repeated characters, at least 12 characters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Relevance&lt;/td&gt;
&lt;td&gt;up to 30&lt;/td&gt;
&lt;td&gt;contains keywords I hand-picked per prompt (15 points each)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Self-confidence&lt;/td&gt;
&lt;td&gt;up to 20&lt;/td&gt;
&lt;td&gt;the model's own average probability of the characters it sampled, times 20&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;matched_kw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;kw&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;kw&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;prompt_info&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"keywords"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;kw&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;kw_score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;30.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matched_kw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;15.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;conf_score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"avg_confidence"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;20.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exploration temperature is lowered each generation: &lt;code&gt;max(0.45, 0.85 - (gen - 1) * 0.12)&lt;/code&gt;, i.e. 0.85, 0.73, 0.61.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;Sources: &lt;code&gt;PAPER.md&lt;/code&gt; and &lt;code&gt;rsi_history.json&lt;/code&gt;. I recomputed the RSI table from &lt;code&gt;rsi_history.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pretraining&lt;/strong&gt; (1,678 characters of Japanese literature excerpts, 377 distinct characters, 800 steps): loss went from 6.1098 at step 1 to 0.0683 at step 800. Prompted with "吾輩は", it produces the opening of &lt;em&gt;I Am a Cat&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dialogue fine-tuning&lt;/strong&gt; (27 Q&amp;amp;A pairs, 1,575 characters, 1,000 steps): loss went from 5.5833 at step 1 to 0.0387 at step 1000.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RSI&lt;/strong&gt; (7 prompts, N=6, threshold 75, 350 steps per generation):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Generation&lt;/th&gt;
&lt;th&gt;Temperature&lt;/th&gt;
&lt;th&gt;Avg best score&lt;/th&gt;
&lt;th&gt;Avg worst score&lt;/th&gt;
&lt;th&gt;Prompts with worst &amp;lt; 75&lt;/th&gt;
&lt;th&gt;Loss after retraining&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Gen 1&lt;/td&gt;
&lt;td&gt;0.85&lt;/td&gt;
&lt;td&gt;97.56&lt;/td&gt;
&lt;td&gt;80.77&lt;/td&gt;
&lt;td&gt;4/7&lt;/td&gt;
&lt;td&gt;0.0635&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gen 2&lt;/td&gt;
&lt;td&gt;0.73&lt;/td&gt;
&lt;td&gt;97.84&lt;/td&gt;
&lt;td&gt;97.80&lt;/td&gt;
&lt;td&gt;0/7&lt;/td&gt;
&lt;td&gt;0.0490&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gen 3&lt;/td&gt;
&lt;td&gt;0.61&lt;/td&gt;
&lt;td&gt;97.84&lt;/td&gt;
&lt;td&gt;97.80&lt;/td&gt;
&lt;td&gt;0/7&lt;/td&gt;
&lt;td&gt;0.0639&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Gen 1 failures looked like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For "こんにちは！元気？" ("Hello! How are you?"), one candidate answered "こんばんは！…" ("Good evening!…") (69.8).&lt;/li&gt;
&lt;li&gt;For "LLMとAttentionについて教えて", one candidate wrote "Attentionって何？\nAI: …" inside its own answer, i.e. role leakage (74.9).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The average worst-case score went from 80.77 to 97.80, and prompts with a failing candidate went from 4/7 to 0/7. But please don't read this as the model getting smarter. Here is why.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations (please read this part)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Very little data.&lt;/strong&gt; Pretraining text is 1,678 characters (about 5 KB); the dialogue set is 27 pairs. Losses of 0.04 to 0.07 mostly mean the model has memorized its data. I never held out a validation set, so there is no generalization number anywhere in this project.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The evaluation prompts are the training prompts.&lt;/strong&gt; The 7 accepted synthetic pairs are answers to exactly the 7 prompts used for scoring (they sit at the end of &lt;code&gt;chat_data.txt&lt;/code&gt;). Gen 2 and Gen 3 are being asked questions whose answers they saw in training. Higher scores are expected and say nothing about unseen questions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The grader is the model itself plus my rules.&lt;/strong&gt; The score comes from rules I wrote, keywords I chose, and the model's own confidence. Self-grading is biased toward whatever fits the rules, and the confidence term tends to reward memorized answers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A confound.&lt;/strong&gt; I also lowered the sampling temperature each generation, which by itself should reduce garbage output. I did not separate the effect of RSI from the effect of temperature.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One recorded run.&lt;/strong&gt; I don't have repeated runs with different seeds, or a comparison against the same setup without RSI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not useful.&lt;/strong&gt; Ask about anything outside the training data and you get an off-topic reply. The README says the same.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So what actually happened is: a tiny model picked its best-scoring answers to 7 questions and re-learned them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install -r requirements.txt   &lt;span class="c"&gt;# torch&amp;gt;=2.0.0&lt;/span&gt;

python mini_gpt.py                &lt;span class="c"&gt;# pretrain and generate&lt;/span&gt;
python chat_gpt.py                &lt;span class="c"&gt;# train on dialogues (saves chat_model.pt)&lt;/span&gt;
python chat_gpt.py --chat         &lt;span class="c"&gt;# chat with the saved model&lt;/span&gt;
python web_ui.py                  &lt;span class="c"&gt;# local web UI (http://localhost:8765)&lt;/span&gt;
python rsi_gpt.py                 &lt;span class="c"&gt;# run 3 RSI generations&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that &lt;code&gt;rsi_gpt.py&lt;/code&gt; rewrites &lt;code&gt;chat_data.txt&lt;/code&gt;, so back it up first. If you only want to poke at it, the demo Space below is easier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A ~0.9M-parameter Japanese GPT fits in plain PyTorch; &lt;code&gt;mini_gpt.py&lt;/code&gt; is 175 lines including comments.&lt;/li&gt;
&lt;li&gt;A prompt format plus a stop character was enough to turn a text-continuation model into a (very small) chat model, with no architecture change.&lt;/li&gt;
&lt;li&gt;The RSI numbers come from a toy setup with self-grading and evaluation prompts leaked into training, so they are not evidence of general self-improvement. If I do this again, I would split off held-out prompts, use a grader other than my own rules, and fix the temperature.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/koheip/mini-llm" rel="noopener noreferrer"&gt;https://github.com/koheip/mini-llm&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Model on Hugging Face: &lt;a href="https://huggingface.co/koheip/mini-gpt-ja" rel="noopener noreferrer"&gt;https://huggingface.co/koheip/mini-gpt-ja&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Demo Space: &lt;a href="https://huggingface.co/spaces/koheip/mini-gpt-ja-demo" rel="noopener noreferrer"&gt;https://huggingface.co/spaces/koheip/mini-gpt-ja-demo&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>pytorch</category>
      <category>llm</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Building Sites That Both Humans and AI Agents Can Read: A Practical Intro to AIO</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Tue, 17 Nov 2026 18:49:36 +0000</pubDate>
      <link>https://dev.to/koheip/building-sites-that-both-humans-and-ai-agents-can-read-a-practical-intro-to-aio-2kp5</link>
      <guid>https://dev.to/koheip/building-sites-that-both-humans-and-ai-agents-can-read-a-practical-intro-to-aio-2kp5</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally published in Japanese on &lt;a href="https://zenn.dev/koheip/articles/aio-site-for-humans-and-ai-agents" rel="noopener noreferrer"&gt;Zenn&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Hi, I'm Kohei Matsunobe, a second-year student at ZEN University studying Intelligent Informatics (online). I build AI agents and apps as personal projects, including an iOS app called Kamimegu and apps built with Expo / React Native.&lt;/p&gt;

&lt;p&gt;I recently wrote this on LinkedIn:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The skills web engineers need from now on are not only "building sites that are easy for humans to read." Building sites that AI agents (such as GrokBot and Muse) can correctly recognize is becoming essential.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When you build AI agents, you notice that an agent is also a &lt;em&gt;reader of the web&lt;/em&gt;. We are moving from a world where people click links in search results to one where agents collect and interpret information on the web and present answers or actions. In that world, the question for site builders is not only how a page looks, but &lt;strong&gt;whether a machine can read its structure without getting it wrong&lt;/strong&gt;. I think of this as DX for AI: Data Experience.&lt;/p&gt;

&lt;p&gt;I call this viewpoint &lt;strong&gt;AIO (AI Optimization)&lt;/strong&gt;. In this article I turn the four points from my post into minimal code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Semantic HTML&lt;/li&gt;
&lt;li&gt;Structured data (JSON-LD)&lt;/li&gt;
&lt;li&gt;Access control with AI crawlers in mind (robots.txt), and llms.txt&lt;/li&gt;
&lt;li&gt;Easy-to-fetch data, APIs, and performance&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A caveat up front: this is not a "do this and AI will definitely pick you up" guide. I haven't verified from primary sources how any specific AI agent parses a site, so I won't claim anything about that. What follows is based on official documentation and specs: how to make pages machine-readable, and how to signal your intent to crawlers.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Semantic HTML: let the tags carry the meaning
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The problem
&lt;/h3&gt;

&lt;p&gt;Two pages can look identical, yet a page made only of &lt;code&gt;div&lt;/code&gt;s doesn't tell a machine which part is the heading, the main content, or the navigation. A human can tell by looking. Something reading the HTML has far fewer clues beyond the tags.&lt;/p&gt;

&lt;h3&gt;
  
  
  Before
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"header"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"logo"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;My Blog&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"menu"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/posts"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Posts&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;What is AIO?&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"date"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;2026-11-18&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Body text...&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"footer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;© 2026&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  After
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;header&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"logo"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;My Blog&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;nav&lt;/span&gt; &lt;span class="na"&gt;aria-label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Main"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/posts"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Posts&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;main&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;article&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;What is AIO?&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;time&lt;/span&gt; &lt;span class="na"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"2026-11-18"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;November 18, 2026&lt;span class="nt"&gt;&amp;lt;/time&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Body text...&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/article&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;footer&amp;gt;&lt;/span&gt;© 2026&lt;span class="nt"&gt;&amp;lt;/footer&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Put the page's primary content in &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt; (one per page).&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt; for self-contained pieces and &lt;code&gt;&amp;lt;nav&amp;gt;&lt;/code&gt; for navigation.&lt;/li&gt;
&lt;li&gt;Use headings in order (&lt;code&gt;h1&lt;/code&gt; → &lt;code&gt;h2&lt;/code&gt; → &lt;code&gt;h3&lt;/code&gt;) without skipping levels. Don't pick a heading tag for its size; use CSS for that.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;&amp;lt;time datetime="..."&amp;gt;&lt;/code&gt; for dates and meaningful &lt;code&gt;alt&lt;/code&gt; text for images.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is also standard accessibility practice (screen readers). Here, "easy for humans to use" and "easy for machines to read" turn out to be the same work.&lt;/p&gt;

&lt;p&gt;References: &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Semantics" rel="noopener noreferrer"&gt;MDN: Semantics&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/main" rel="noopener noreferrer"&gt;MDN: &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Side note: if your content only appears in the HTML after JavaScript runs, clients that don't execute JavaScript will see nothing. Whether a client runs JavaScript is up to that client, so it's safer to include important content in the initial HTML response (SSR / SSG). If you export Expo or React Native code to the web, keep this in mind for the pages you want to be read, such as a product page.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  2. Structured data (JSON-LD): add meaning in a machine-readable form
&lt;/h2&gt;

&lt;p&gt;Semantic HTML describes a document's skeleton. Structured data states what a page is &lt;em&gt;about&lt;/em&gt; (an article, an app, who wrote it) using the &lt;a href="https://schema.org/" rel="noopener noreferrer"&gt;Schema.org&lt;/a&gt; vocabulary. Google recommends JSON-LD as the format (&lt;a href="https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data" rel="noopener noreferrer"&gt;Google: Intro to structured data&lt;/a&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  An article page (Article)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"application/ld+json"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"@context"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://schema.org"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Article"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"headline"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"What is AIO?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"datePublished"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-18T09:00:00+09:00"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"dateModified"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-18T09:00:00+09:00"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s2"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Person"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Kohei Matsunobe"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://zenn.dev/koheip"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"image"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"https://example.com/images/aio-cover.png"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Google's Article documentation says there are no required properties; you add the recommended ones that apply (&lt;a href="https://developers.google.com/search/docs/appearance/structured-data/article" rel="noopener noreferrer"&gt;Google: Article structured data&lt;/a&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  An app landing page (SoftwareApplication)
&lt;/h3&gt;

&lt;p&gt;For an app's landing page, &lt;code&gt;SoftwareApplication&lt;/code&gt; fits. These are dummy values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"application/ld+json"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"@context"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://schema.org"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"SoftwareApplication"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Sample App"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"operatingSystem"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"iOS"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"applicationCategory"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"LifestyleApplication"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"offers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Offer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"price"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"priceCurrency"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"JPY"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two notes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keep the values consistent with what the page actually says.&lt;/strong&gt; Don't put ratings or prices only in structured data when they don't appear on the page.&lt;/li&gt;
&lt;li&gt;If you want Google's software app rich result, there are required properties of its own: &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;offers.price&lt;/code&gt;, and &lt;code&gt;aggregateRating&lt;/code&gt; or &lt;code&gt;review&lt;/code&gt; (&lt;a href="https://developers.google.com/search/docs/appearance/structured-data/software-app" rel="noopener noreferrer"&gt;Google: Software app&lt;/a&gt;). If no real ratings or reviews exist, don't invent them. As a Schema.org vocabulary, the minimal form above is still valid.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can browse the available types and properties at &lt;a href="https://schema.org/Article" rel="noopener noreferrer"&gt;Schema.org/Article&lt;/a&gt; and &lt;a href="https://schema.org/SoftwareApplication" rel="noopener noreferrer"&gt;Schema.org/SoftwareApplication&lt;/a&gt;. Adding structured data doesn't guarantee that any particular AI agent will use it. For Google Search features, the docs above are the primary source.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Crawler-aware access control: robots.txt and llms.txt
&lt;/h2&gt;

&lt;h3&gt;
  
  
  robots.txt: signal your intent per crawler
&lt;/h3&gt;

&lt;p&gt;What matters here is that &lt;strong&gt;crawlers have different purposes&lt;/strong&gt;. The vendors' own docs draw these distinctions:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;User agent / token&lt;/th&gt;
&lt;th&gt;Vendor&lt;/th&gt;
&lt;th&gt;Purpose as stated in the docs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;GPTBot&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;OpenAI&lt;/td&gt;
&lt;td&gt;Crawling content that may be used to train generative AI foundation models&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;OAI-SearchBot&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;OpenAI&lt;/td&gt;
&lt;td&gt;Surfacing sites in ChatGPT's search features&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ChatGPT-User&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;OpenAI&lt;/td&gt;
&lt;td&gt;User-initiated actions. Not automatic crawling; the docs say robots.txt rules may not apply&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ClaudeBot&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Anthropic&lt;/td&gt;
&lt;td&gt;Collecting web content that could contribute to training generative AI models&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Claude-SearchBot&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Anthropic&lt;/td&gt;
&lt;td&gt;Improving the quality of search results&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Claude-User&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Anthropic&lt;/td&gt;
&lt;td&gt;Access when a Claude user asks a question&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Google-Extended&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Google&lt;/td&gt;
&lt;td&gt;A token controlling whether crawled content may be used for training future Gemini models. It doesn't affect inclusion in Google Search, and has no separate HTTP user agent string&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PerplexityBot&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Perplexity&lt;/td&gt;
&lt;td&gt;Surfacing and linking sites in Perplexity search results. Stated as not used for foundation model training&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Perplexity-User&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Perplexity&lt;/td&gt;
&lt;td&gt;User-initiated actions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;(Sources at the end. Names and descriptions can change, so check each vendor's latest docs before configuring.)&lt;/p&gt;

&lt;p&gt;With that in mind, a policy like "don't use my content for training, but I'm happy to appear in search" can be written like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Opt out of use for generative AI training
User-agent: GPTBot
Disallow: /

User-agent: ClaudeBot
Disallow: /

User-agent: Google-Extended
Disallow: /

# Allow crawlers that power search results
User-agent: OAI-SearchBot
Allow: /

User-agent: Claude-SearchBot
Allow: /

User-agent: PerplexityBot
Allow: /

# Everyone else: business as usual
User-agent: *
Allow: /

Sitemap: https://example.com/sitemap.xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to allow everything, writing nothing (or &lt;code&gt;Allow: /&lt;/code&gt; under &lt;code&gt;User-agent: *&lt;/code&gt;) is enough. Which one is right depends on your site's policy.&lt;/p&gt;

&lt;p&gt;Things to keep in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;robots.txt is a convention, not enforcement.&lt;/strong&gt; The protocol spec, &lt;a href="https://www.rfc-editor.org/rfc/rfc9309" rel="noopener noreferrer"&gt;RFC 9309&lt;/a&gt;, itself says the rules are "not a form of access authorization." Whether to obey is up to the crawler. If something really must stay private, require authentication or don't publish it.&lt;/li&gt;
&lt;li&gt;User-initiated agents (such as &lt;code&gt;ChatGPT-User&lt;/code&gt;) may be treated differently from crawlers regarding robots.txt, as the table above notes.&lt;/li&gt;
&lt;li&gt;OpenAI and Perplexity publish their crawlers' IP ranges, so you can also use a WAF to tell real crawlers from requests that merely claim the user agent (see each vendor's docs).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  llms.txt: a proposed "front door" for AI
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;llms.txt&lt;/code&gt; is a proposal by Jeremy Howard: a Markdown file summarizing a site for AI agents, placed at &lt;code&gt;/llms.txt&lt;/code&gt; or another path.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important: llms.txt is not a standard. It's a proposal.&lt;/strong&gt; The spec page itself is worded "We propose...". Also, not every AI service reads it, and I haven't found a primary source confirming that any particular AI always does. I'd be wary of claims like "add it and your ranking or citations will go up" unless evidence is shown.&lt;/p&gt;

&lt;p&gt;I still think it's worth trying because it's cheap. Per the spec (&lt;a href="https://llmstxt.org/" rel="noopener noreferrer"&gt;llmstxt.org&lt;/a&gt;), the file contains, in this order:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An H1 with the name of the project or site (&lt;strong&gt;the only required section&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;A blockquote with a short summary&lt;/li&gt;
&lt;li&gt;Optional: further Markdown (anything except headings)&lt;/li&gt;
&lt;li&gt;Optional: H2 sections containing file lists (&lt;code&gt;[name](url): notes&lt;/code&gt;). By convention, an &lt;code&gt;## Optional&lt;/code&gt; section holds secondary links that can be skipped when a shorter context is needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example (a fictional blog):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;# My Blog
&lt;/span&gt;
&lt;span class="ge"&gt;&amp;gt; A tech blog about AI agents and app development, based on personal projects.
&lt;/span&gt;
Articles are in Japanese. Code samples are included in each article.

&lt;span class="gu"&gt;## Articles
&lt;/span&gt;
&lt;span class="k"&gt;- &lt;/span&gt;[What is AIO?](https://example.com/posts/aio.md): An intro to semantic HTML, JSON-LD, robots.txt, and llms.txt
&lt;span class="k"&gt;- &lt;/span&gt;[Building apps with Expo](https://example.com/posts/expo.md): Notes on solo development with Expo / React Native

&lt;span class="gu"&gt;## Profile
&lt;/span&gt;
&lt;span class="k"&gt;- &lt;/span&gt;[About me](https://example.com/about.md): Author profile

&lt;span class="gu"&gt;## Optional
&lt;/span&gt;
&lt;span class="k"&gt;- &lt;/span&gt;[Archive](https://example.com/archive.md)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same spec page also proposes serving clean Markdown versions of pages (&lt;code&gt;page.html.md&lt;/code&gt; or &lt;code&gt;page.md&lt;/code&gt;), without ads or navigation, for the links to point to.&lt;/p&gt;

&lt;p&gt;On "access control": llms.txt is not control but &lt;strong&gt;guidance&lt;/strong&gt;. It helps to separate roles: robots.txt for allow/deny signals, llms.txt for guidance.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Easy-to-fetch data, APIs, and performance
&lt;/h2&gt;

&lt;p&gt;This last point is unglamorous, but I think it's the most "engineer" part. These are my opinions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stable URLs and URL design:&lt;/strong&gt; if the same content is scattered across multiple URLs, readers get confused. Specify a canonical URL (&lt;code&gt;&amp;lt;link rel="canonical" href="..."&amp;gt;&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provide machine-oriented exits:&lt;/strong&gt; a sitemap (&lt;code&gt;sitemap.xml&lt;/code&gt;), RSS/Atom, and, for data that's fine to publish, a JSON API. If there's a route that doesn't require scraping HTML, it's easier for both readers and builders.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Return correct status codes:&lt;/strong&gt; avoid returning &lt;code&gt;200&lt;/code&gt; for pages that don't exist (soft 404s).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Be light and fast:&lt;/strong&gt; heavy pages can affect how much gets crawled and cause timeouts, and they're a worse experience for humans too. Decide what "fast" means by measuring (I won't cite numbers here).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accessibility:&lt;/strong&gt; keyboard operation, &lt;code&gt;alt&lt;/code&gt; text, labeled form fields. Like semantic HTML, it helps both people and machines.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A checklist to apply to your own site
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Main content is structured with &lt;code&gt;main&lt;/code&gt; / &lt;code&gt;article&lt;/code&gt; / &lt;code&gt;h1&lt;/code&gt;…&lt;/li&gt;
&lt;li&gt;[ ] Important content is in the HTML before JavaScript runs&lt;/li&gt;
&lt;li&gt;[ ] JSON-LD (Article / SoftwareApplication, etc.) that matches the page content&lt;/li&gt;
&lt;li&gt;[ ] A robots.txt policy that separates training, search, and user-initiated access&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.toOptional"&gt; &lt;/a&gt; An llms.txt, with the understanding that its effect isn't guaranteed&lt;/li&gt;
&lt;li&gt;[ ] Canonical URL, sitemap, and correct status codes&lt;/li&gt;
&lt;li&gt;[ ] Measured performance and fixed the slow spots&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I plan to review my own app landing pages and tech blog against this list.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;My concern is this: a site that AI can't find, or can't understand the structure of, is becoming as good as nonexistent. But how each agent reads the web differs and will keep changing. That's why I think the durable move, for humans and AI alike, is not a quick trick for one specific AI, but &lt;strong&gt;writing meaning down properly, following standards&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Are you already starting to optimize for AI agents in your projects? I'd love to hear in the comments.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://llmstxt.org/" rel="noopener noreferrer"&gt;llms.txt spec (llmstxt.org)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://schema.org/" rel="noopener noreferrer"&gt;Schema.org&lt;/a&gt; / &lt;a href="https://schema.org/Article" rel="noopener noreferrer"&gt;Article&lt;/a&gt; / &lt;a href="https://schema.org/SoftwareApplication" rel="noopener noreferrer"&gt;SoftwareApplication&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data" rel="noopener noreferrer"&gt;Google: Intro to structured data&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/search/docs/appearance/structured-data/article" rel="noopener noreferrer"&gt;Google: Article structured data&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/search/docs/appearance/structured-data/software-app" rel="noopener noreferrer"&gt;Google: Software app structured data&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developers.google.com/crawling/docs/crawlers-fetchers/overview-google-crawlers" rel="noopener noreferrer"&gt;Google: Crawlers overview&lt;/a&gt; / &lt;a href="https://developers.google.com/crawling/docs/crawlers-fetchers/google-common-crawlers" rel="noopener noreferrer"&gt;Google's common crawlers (Google-Extended)&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.openai.com/api/docs/bots" rel="noopener noreferrer"&gt;OpenAI: Overview of OpenAI Crawlers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://privacy.claude.com/en/articles/8896518-does-anthropic-crawl-data-from-the-web-and-how-can-site-owners-block-the-crawler" rel="noopener noreferrer"&gt;Anthropic: Does Anthropic crawl data from the web...&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.perplexity.ai/docs/resources/perplexity-crawlers" rel="noopener noreferrer"&gt;Perplexity: Perplexity Crawlers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc9309" rel="noopener noreferrer"&gt;RFC 9309: Robots Exclusion Protocol&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Semantics" rel="noopener noreferrer"&gt;MDN: Semantics&lt;/a&gt; / &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/main" rel="noopener noreferrer"&gt;MDN: &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>seo</category>
      <category>html</category>
    </item>
    <item>
      <title>I Built Three Tools for Trusting AI Agents: Stop Them, Don't Give Them Keys, Make Them Visible</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Tue, 17 Nov 2026 12:44:44 +0000</pubDate>
      <link>https://dev.to/koheip/i-built-three-tools-for-trusting-ai-agents-stop-them-dont-give-them-keys-make-them-visible-1ob1</link>
      <guid>https://dev.to/koheip/i-built-three-tools-for-trusting-ai-agents-stop-them-dont-give-them-keys-make-them-visible-1ob1</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally published in Japanese on &lt;a href="https://zenn.dev/koheip/articles/ai-agent-stop-keyless-visible" rel="noopener noreferrer"&gt;Zenn&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Hi, I'm Kohei Matsunobe, a second-year student at ZEN University studying Intelligent Informatics (online). I'm working toward becoming an engineer who builds and uses AI agents, and I do that through personal projects.&lt;/p&gt;

&lt;p&gt;In October 2026, I built three open-source projects around AI agents.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;In a sentence&lt;/th&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Yata (ヤタ)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A Japanese-first personal AI assistant that runs on your own PC&lt;/td&gt;
&lt;td&gt;Python / TypeScript&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;kagi (鍵, "key")&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A secret broker that keeps real API keys out of an AI agent's hands&lt;/td&gt;
&lt;td&gt;Go&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Omoikane (オモイカネ)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A screen that shows what Claude Code is doing, at a glance, in plain Japanese&lt;/td&gt;
&lt;td&gt;TypeScript&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;They may look like separate projects, but once I finished them, I realized they were all trying to answer the same question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What do you need in order to trust an AI agent with real work?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;My own answer is these three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Stop them before a dangerous action&lt;/strong&gt; (Yata's confirmation gate)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't give them the keys in the first place&lt;/strong&gt; (kagi)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make what they're doing visible&lt;/strong&gt; (Omoikane)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This article covers the design decisions behind each one, and what I learned by building them.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I developed all three while consulting with Claude Code (the VS Code extension). I decide the direction of the design and what to build or not to build; implementation is a two-person effort with the AI.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. Yata: An agent that can be stopped
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/koheip/yata" rel="noopener noreferrer"&gt;https://github.com/koheip/yata&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What it is
&lt;/h3&gt;

&lt;p&gt;Yata is an AI assistant you talk to in chat, and it helps with work using web search, page reading, browser automation, Gmail/Calendar, LINE, and more. The name comes from Yatagarasu (八咫烏), the three-legged crow that guided Emperor Jimmu.&lt;/p&gt;

&lt;p&gt;Here is what it does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Runs locally&lt;/strong&gt;: conversations and memory are stored in SQLite on your PC&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You can choose the AI&lt;/strong&gt;: Gemini / OpenAI / Anthropic / xAI / DeepSeek, plus local LLMs such as Ollama and LM Studio&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connects to Japanese services&lt;/strong&gt;: Chatwork, Backlog, kintone, freee, Money Forward Cloud Invoice, Rakuten Ichiba, LINE&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Japanese business calculations&lt;/strong&gt;: public holidays, business days, the Japanese calendar (wareki), and consumption tax under the invoice system&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Routines&lt;/strong&gt;: if you ask in chat to "summarize the news every morning at 8," APScheduler runs it every day&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fully offline mode&lt;/strong&gt;: uses only a local LLM and disables every tool that goes out to the network&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Architecture
&lt;/h3&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TB
  UI["Chat UI&amp;lt;br/&amp;gt;React + TypeScript"]
  API["FastAPI&amp;lt;br/&amp;gt;conversations, SSE, confirmation"]
  Loop["Agent loop"]
  Policy["ToolPolicy"]
  Gate["ConfirmationGate"]
  Router["ModelRouter"]
  Registry["ToolRegistry"]
  DB[("SQLite&amp;lt;br/&amp;gt;conversations and memory")]

  UI --&amp;gt;|message| API
  UI --&amp;gt;|approve / deny| Gate
  API --&amp;gt; Loop
  API --&amp;gt; DB
  Loop --&amp;gt; Router
  Loop --&amp;gt; Policy
  Policy --&amp;gt; Gate
  Loop --&amp;gt; Registry&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The backend is Python (FastAPI), and the UI is React + TypeScript. The agent loop, Playwright, and SQLite live in the same process. Intermediate events (&lt;code&gt;tool_call&lt;/code&gt; / &lt;code&gt;tool_result&lt;/code&gt; / &lt;code&gt;confirmation_required&lt;/code&gt;, and so on) are streamed to the UI over Server-Sent Events.&lt;/p&gt;

&lt;h3&gt;
  
  
  Design choice 1: Give tools a "risk," and let the loop just ask
&lt;/h3&gt;

&lt;p&gt;A tool is a class with a name, a JSON Schema, a risk, and an execute function. I defined four risk levels.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Risk&lt;/th&gt;
&lt;th&gt;Examples&lt;/th&gt;
&lt;th&gt;Handling&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;read&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Search, page reading, reading Gmail&lt;/td&gt;
&lt;td&gt;Run immediately&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;write&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Saving local memory, drafting email&lt;/td&gt;
&lt;td&gt;Run immediately&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mutate&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Browser clicks and typing&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Confirm first&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;external&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sending email, creating or deleting events, payments&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Confirm first&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The agent loop only asks &lt;code&gt;ToolPolicy&lt;/code&gt; "does this tool need confirmation?" — it does not special-case individual tools. When you add a new dangerous tool, you register it with &lt;code&gt;Risk.EXTERNAL&lt;/code&gt; and it joins the same confirmation flow.&lt;/p&gt;

&lt;p&gt;The confirmation gate uses an &lt;code&gt;asyncio.Future&lt;/code&gt; to connect the agent loop with an approval request from the UI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;InMemoryConfirmationGate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_pending&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Future&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;request_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uuid4&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;hex&lt;/span&gt;
        &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_pending&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;request_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_running_loop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_future&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;request_id&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;wait&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;future&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_pending&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;future&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;wait_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;future&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;TimeoutError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;  &lt;span class="c1"&gt;# timeouts are treated as "deny"&lt;/span&gt;
        &lt;span class="k"&gt;finally&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_pending&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;approved&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;future&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_pending&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;future&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;future&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;done&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
        &lt;span class="n"&gt;future&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set_result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;approved&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Timeouts fall back to "deny." The policy is: when in doubt, don't run it.&lt;/p&gt;

&lt;p&gt;If a dangerous tool is called from a routine (when nobody is looking at the screen), it does not run on its own. It stops in a "waiting for confirmation" state, and the next time you open the UI, you're asked to approve or deny. When you use it from LINE, the message shows "Approve" and "Deny" buttons.&lt;/p&gt;

&lt;h3&gt;
  
  
  Design choice 2: Skip the LLM wrapper, and put the differences where you can see them
&lt;/h3&gt;

&lt;p&gt;I considered a unified wrapper like LiteLLM for swapping models, but this time I used the official SDKs (&lt;code&gt;google-genai&lt;/code&gt;, &lt;code&gt;openai&lt;/code&gt;, &lt;code&gt;anthropic&lt;/code&gt;) directly.&lt;/p&gt;

&lt;p&gt;The provider interface is a single &lt;code&gt;complete(messages, tools, model)&lt;/code&gt;. Vendor differences — especially &lt;strong&gt;how tool results are returned&lt;/strong&gt; — are confined to one place: &lt;code&gt;convert.py&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OpenAI: a &lt;code&gt;tool&lt;/code&gt;-role message&lt;/li&gt;
&lt;li&gt;Anthropic: a &lt;code&gt;tool_result&lt;/code&gt; block&lt;/li&gt;
&lt;li&gt;Gemini: a &lt;code&gt;function_response&lt;/code&gt; part&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A wrapper would mean less code, but more dependencies, and it becomes harder to see where and what is being converted. This is a personal project that also serves as learning and a portfolio, so I chose the option where the differences stay readable. OpenAI-compatible servers such as Ollama work just by changing the &lt;code&gt;base_url&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Design choice 3: Minimize the surface that faces the outside
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Page reading inspects the URL on every redirect, and always rejects cloud metadata addresses (such as &lt;code&gt;169.254.169.254&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;The LINE webhook is served on a separate server (port 8742) from the main UI (port 8741), exposing only &lt;code&gt;/line/webhook&lt;/code&gt;. Incoming requests are filtered with signature verification and a userId allowlist&lt;/li&gt;
&lt;li&gt;Yata starts the cloudflared tunnel automatically, and re-registers the webhook URL with LINE whenever the URL changes&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  After building it: setup was far too hard
&lt;/h3&gt;

&lt;p&gt;I published v0.1.0 and used it myself every day. The biggest problem wasn't the features — it was &lt;strong&gt;how hard setup was&lt;/strong&gt;. Google integration in particular (creating an OAuth client in Cloud Console) and LINE integration (official account, channel, webhook) have so many steps that they're basically impossible for a typical person.&lt;/p&gt;

&lt;p&gt;I've been chipping away at it — letting you paste API keys in the app, reducing install to a one-liner, automating the LINE tunnel — but the structure is still there: the more integrations you add, the more setup you get. That's the next problem to solve.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. kagi: Don't give agents the keys
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/koheip/kagi" rel="noopener noreferrer"&gt;https://github.com/koheip/kagi&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why I built it
&lt;/h3&gt;

&lt;p&gt;While building Yata, what worried me was &lt;strong&gt;how API keys get passed around&lt;/strong&gt;. If you give a long-lived API key to an LLM agent as an environment variable, a prompt injection from a malicious web page or email could be enough to send the key outside.&lt;/p&gt;

&lt;p&gt;So I built &lt;strong&gt;kagi&lt;/strong&gt;, a broker that sits between the agent and the API, in Go. All the agent holds is an &lt;strong&gt;mTLS client certificate&lt;/strong&gt; and a &lt;strong&gt;token that expires in a few minutes&lt;/strong&gt;. The real key is injected by kagi at request time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; AI Agent ──mTLS + short-lived token──▶ kagid ──HTTPS + real key──▶ OpenAI, etc.
 (does not know the key)                 │ token verification, allowlist
                                        │ request caps, SSRF prevention
                                        │ response redaction
                                        └─ hash-chain audit log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It has zero dependencies (Go standard library only), which keeps the supply-chain attack surface small.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mapping to the OWASP Top 10 for LLM
&lt;/h3&gt;

&lt;p&gt;The design was about attaching a countermeasure to each of the recent problems, one by one.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Problem&lt;/th&gt;
&lt;th&gt;kagi's countermeasure&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Secret leakage via prompt injection (LLM01/02)&lt;/td&gt;
&lt;td&gt;The agent never knows the key. Even if the upstream echoes the key, it is redacted&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Excessive privileges (LLM06)&lt;/td&gt;
&lt;td&gt;Method + path allowlist (deny by default)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unbounded consumption (LLM10)&lt;/td&gt;
&lt;td&gt;Per-token request caps, per-agent rate limits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Token theft&lt;/td&gt;
&lt;td&gt;Tokens are bound to the client certificate (in the spirit of RFC 8705)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SSRF / DNS rebinding&lt;/td&gt;
&lt;td&gt;Block private destinations using the resolved IP &lt;strong&gt;after&lt;/strong&gt; DNS lookup&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Harvest now, decrypt later&lt;/td&gt;
&lt;td&gt;Prefer X25519MLKEM768 (ML-KEM hybrid) on TLS 1.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Audit log tampering&lt;/td&gt;
&lt;td&gt;An HMAC hash chain detects even a one-character change&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Design choice 1: Bind the token to the certificate
&lt;/h3&gt;

&lt;p&gt;Tokens are signed with Ed25519 and include the SHA-256 thumbprint of the client certificate (the &lt;code&gt;cnf&lt;/code&gt; claim). Even if a token leaks from a log, an agent with a different certificate can't use it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;== A different agent that stole the token tries to use it → 401 (certificate binding)
{"error":"token not bound to this client certificate"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Design choice 2: Redaction that works across chunk boundaries
&lt;/h3&gt;

&lt;p&gt;In case a real key ends up in an upstream API response (for example, echoed in an error message), kagi redacts keys from the response.&lt;/p&gt;

&lt;p&gt;The hard part was &lt;strong&gt;streaming&lt;/strong&gt;. SSE responses arrive in fragments, so if a key is split across two chunks, a naive replacement will miss it. I keep "key length − 1 bytes" to carry over into the next read, so matches that cross a boundary can still be detected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="nf"&gt;mask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pend&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;   &lt;span class="c1"&gt;// carry over the part that might cross a boundary&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;eof&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pend&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;cut&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pend&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pend&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;cut&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pend&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cut&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the tests, I feed the stream through &lt;code&gt;iotest.OneByteReader&lt;/code&gt; so it is read one byte at a time, and confirm that it does not leak even under the worst splitting. Also, matches can't be detected in compressed responses, so kagi forces &lt;code&gt;Accept-Encoding: identity&lt;/code&gt; on the upstream request.&lt;/p&gt;

&lt;h3&gt;
  
  
  Design choice 3: Encryption at rest, and "if it fails, stop"
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Secrets use &lt;strong&gt;envelope encryption&lt;/strong&gt;: passphrase → (PBKDF2-SHA256, 600,000 iterations → HKDF) → KEK, and a DEK per secret (AES-256-GCM). The secret's name goes into the AAD, so ciphertext swapping can be detected&lt;/li&gt;
&lt;li&gt;Changing the passphrase only re-wraps the DEKs; the secrets' ciphertext does not change&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fail-closed&lt;/strong&gt;: if the audit log can't be written, the request is not executed&lt;/li&gt;
&lt;li&gt;Unknown fields in the policy are a load error (to prevent a typo from widening permissions)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you run the demo script (&lt;code&gt;./scripts/demo.sh&lt;/code&gt;), you can walk through everything from CA issuance to attack scenarios (key echoing, token theft, audit-log tampering).&lt;/p&gt;

&lt;h3&gt;
  
  
  Almost no change on the caller side
&lt;/h3&gt;

&lt;p&gt;On the agent side, you just swap the OpenAI SDK's &lt;code&gt;base_url&lt;/code&gt; and certificates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://localhost:8443/v1/proxy/openai/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;# kagi's short-lived token (not the real key)&lt;/span&gt;
    &lt;span class="n"&gt;http_client&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;httpx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cert&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pki/yata.crt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"pki/yata.key"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;verify&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"pki/ca.crt"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  3. Omoikane: Make the agent's activity visible
&lt;/h2&gt;

&lt;h3&gt;
  
  
  It started as an orchestrator
&lt;/h3&gt;

&lt;p&gt;I originally started Omoikane as an &lt;strong&gt;AI agent orchestrator&lt;/strong&gt;. It splits Claude Code into "implementer → tester → test runner → reviewer," and a conductor assigns the work. The name comes from Omoikane-no-kami (思金神), the deity of wisdom who assigned roles to the gods in the myth of the Heavenly Rock Cave (Ama-no-Iwato).&lt;/p&gt;

&lt;p&gt;At that stage I built mechanisms like these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each role is run with &lt;code&gt;claude -p --output-format stream-json&lt;/code&gt;, and the output is read line by line and converted into common events&lt;/li&gt;
&lt;li&gt;Test pass/fail is &lt;strong&gt;not self-reported by the role; Omoikane runs the test command itself and judges the result&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;If tests or review fail, the work is sent back to the implementer, up to a retry limit&lt;/li&gt;
&lt;li&gt;Each role works on a dedicated branch in a git worktree, so it doesn't break your local work&lt;/li&gt;
&lt;li&gt;Before a merge, it always stops until a person presses "Approve"&lt;/li&gt;
&lt;li&gt;Besides Claude, the roles can be switched to ChatGPT / Grok / DeepSeek / Gemini&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  A change in direction: what really excited me was the visible screen
&lt;/h3&gt;

&lt;p&gt;Along the way, I started to wonder: "Would I actually use this orchestrator in my own work?" Whether splitting into roles is really better is something I won't know until I evaluate it.&lt;/p&gt;

&lt;p&gt;What I enjoyed most while building it, though, was &lt;strong&gt;the screen where the agent's activity streams by in real time&lt;/strong&gt;. So I changed direction, and made the main feature a &lt;strong&gt;"watch UI" that reads the session logs of the Claude Code you already use, from the side&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run watch        &lt;span class="c"&gt;# watch your everyday Claude Code → http://localhost:4318&lt;/span&gt;
npm run watch:demo   &lt;span class="c"&gt;# try it without Claude Code&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Omoikane only reads the JSON Lines under &lt;code&gt;~/.claude/projects&lt;/code&gt;. It writes nothing to Claude Code or to the logs.&lt;/p&gt;

&lt;p&gt;Here's what you can see on the screen:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Now&lt;/strong&gt;: working, thinking, your turn, or stopped, plus a one-line status like "Rewriting a file: src/app.ts"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session list&lt;/strong&gt;: an overview of multiple sessions on one screen&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tokens and cost&lt;/strong&gt;: a breakdown of input, output, and cache, plus counts per sub-agent&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Files touched and commands run&lt;/strong&gt;: read/write counts, and whether commands succeeded&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Notifications&lt;/strong&gt;: when it's your turn, when a question arrives, or when it might be stuck&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Design choice 1: Don't use fs.watch; only read the appended part
&lt;/h3&gt;

&lt;p&gt;File-change detection with &lt;code&gt;fs.watch&lt;/code&gt; is unreliable depending on the OS, so I switched to polling every second. For each file I remember the position (offset) I've already read, and I read &lt;strong&gt;only the newly appended lines&lt;/strong&gt;. For large files, I initially read only the last 8 MB and discard a truncated first line.&lt;/p&gt;

&lt;p&gt;The log format changes a little with Claude Code versions, so &lt;strong&gt;unknown lines are silently skipped&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Design choice 2: Prevent double-counting tokens
&lt;/h3&gt;

&lt;p&gt;Token display ran into a quirk of streaming. The same message's &lt;code&gt;usage&lt;/code&gt; arrives many times, and &lt;code&gt;output_tokens&lt;/code&gt; is a cumulative value. If you simply add them up, the numbers balloon several times over.&lt;/p&gt;

&lt;p&gt;So I &lt;strong&gt;keep only the latest (maximum) value per message ID, and sum those&lt;/strong&gt;. When a run finishes, I cross-check against the result event's &lt;code&gt;modelUsage&lt;/code&gt; (which also includes smaller models used in the background).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TokenMeter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;perMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Usage&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;messageId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;RawUsage&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;messageId&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;perMessage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;messageId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="no"&gt;ZERO_USAGE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// take the max instead of adding (output_tokens is cumulative)&lt;/span&gt;
    &lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;perMessage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;messageId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;maxUsage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;fromRaw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// on completion, cross-check against modelUsage&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Design choice 3: Be honest that "might be stuck" is a guess
&lt;/h3&gt;

&lt;p&gt;Claude Code's logs don't directly say whether it's waiting for permission. So when a tool result hasn't come back for 45 seconds for a command, or 20 seconds otherwise, the UI shows "It may be waiting for permission, or it may just be a long-running task." I made it clear in the UI and the README that this is a guess.&lt;/p&gt;




&lt;h2&gt;
  
  
  Putting the three together
&lt;/h2&gt;

&lt;p&gt;Returning to the original question, the three tools divide the work like this:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
  Human["Human"]
  Agent["AI agent"]
  Omoikane["Omoikane&amp;lt;br/&amp;gt;make it visible"]
  Yata["Yata's confirmation gate&amp;lt;br/&amp;gt;stop them"]
  Kagi["kagi&amp;lt;br/&amp;gt;don't give them the keys"]
  API["External API"]

  Agent --&amp;gt;|dangerous action| Yata
  Yata --&amp;gt;|ask for approval| Human
  Agent --&amp;gt;|short-lived token| Kagi
  Kagi --&amp;gt;|inject the real key| API
  Agent -.logs.-&amp;gt; Omoikane
  Omoikane -.notify.-&amp;gt; Human&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stop them&lt;/strong&gt;: before a dangerous action, ask a person&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't give them the keys&lt;/strong&gt;: don't give the agent things that would be a problem if they were stolen&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make it visible&lt;/strong&gt;: so a person can immediately see what's going on&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My takeaway from building them is that any one of these isn't enough. Only in combination do you start to get closer to "I can trust this with the work."&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned by building them
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Safety is decided by the defaults&lt;/strong&gt;: a timeout is a denial, an unknown field is an error, and if the audit log can't be written, you stop. If you build it so that, when in doubt, it falls toward the safe side, you have fewer things to worry about later&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leave abstraction in the places where differences should stay visible&lt;/strong&gt;: whether you're swapping LLMs or rendering an agent UI, if you define one common event type and confine vendor/tool differences to adapters, it's easier to change the internals later&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What you want to build is allowed to change as you build it&lt;/strong&gt;: Omoikane shifted from an orchestrator to a watch UI, but the event conversion and Japanese-localization pieces I built for the orchestrator still carried over&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You don't know until you use it&lt;/strong&gt;: the more features I added to Yata, the heavier setup became, and it got hard even for me to use. The first user is yourself&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Yata&lt;/strong&gt;: reduce setup effort (make initial integration setup more automatic). Distribution via the Microsoft Store&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;kagi&lt;/strong&gt;: integration with Yata and Omoikane (borrow the key only when pushing or creating a PR). A setup where the actual keys live in AWS Secrets Manager&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Omoikane&lt;/strong&gt;: compare solving a task with a single agent versus splitting it into roles, using an evaluation task set&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Closing
&lt;/h2&gt;

&lt;p&gt;All three are released under the MIT License (Omoikane is being prepared for release). I'd be very happy to get issues or feedback.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Yata: &lt;a href="https://github.com/koheip/yata" rel="noopener noreferrer"&gt;https://github.com/koheip/yata&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;kagi: &lt;a href="https://github.com/koheip/kagi" rel="noopener noreferrer"&gt;https://github.com/koheip/kagi&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>security</category>
      <category>python</category>
      <category>go</category>
    </item>
    <item>
      <title>What Happens When You Tell an LLM a Story Backward?</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Sat, 07 Nov 2026 10:58:12 +0000</pubDate>
      <link>https://dev.to/koheip/what-happens-when-you-tell-an-llm-a-story-backward-1hj0</link>
      <guid>https://dev.to/koheip/what-happens-when-you-tell-an-llm-a-story-backward-1hj0</guid>
      <description>&lt;h2&gt;
  
  
  Fluent answers are not the whole story
&lt;/h2&gt;

&lt;p&gt;When I build with an LLM, I usually start with practical questions: Is the answer useful? Can someone check its sources? Does it make sense?&lt;/p&gt;

&lt;p&gt;That last question hides several different problems. An answer can be grammatically correct and still put events in a strange order. How could we measure that distinction without simply asking another model to judge it?&lt;/p&gt;

&lt;p&gt;I'm Kohei Matsunobe, a second-year correspondence student at ZEN University. I build KamiMeg, an iOS goshuin (shrine-stamp) app with a generative-AI shrine guide, and a Japanese PDF RAG demo that makes its sources visible. A recent paper by Takahiro Sagawa, a professor in the Department of Applied Physics, Graduate School of Engineering at the University of Tokyo, caught my attention because it approaches this question from an unexpected direction: stochastic thermodynamics.&lt;/p&gt;

&lt;p&gt;This is a builder's reading note based on the university's press release and the paper's abstract, not a reproduction of its experiments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Change the order, not the words
&lt;/h2&gt;

&lt;p&gt;Consider this example, translated from the press release:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The cup fell on the floor. The cup broke.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now reverse the sentences:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The cup broke. The cup fell on the floor.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Both versions contain readable sentences. But the first follows a familiar progression; the second makes me look for a different explanation. It is not impossible, just different.&lt;/p&gt;

&lt;p&gt;The research compares how likely such sequences are under a language model. Crucially, it reverses &lt;strong&gt;sentence order while preserving the word order inside each sentence&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Reversing every token would break grammar. The resulting probability difference could mostly reflect broken syntax rather than anything interesting about events. Sentence-level reversal is a way to change the relationship between sentences without destroying their internal structure.&lt;/p&gt;

&lt;p&gt;That experimental choice is what first made the work click for me: a useful measurement starts by deciding what to disturb and what to leave intact.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thermodynamics without measuring GPU heat
&lt;/h2&gt;

&lt;p&gt;The quantity at the center of the paper is &lt;strong&gt;entropy production&lt;/strong&gt;: a way to quantify irreversibility by comparing the likelihood of forward and reversed sequences.&lt;/p&gt;

&lt;p&gt;Here, thermodynamics does not mean measuring the computer's physical heat output or energy consumption. The object of study is the model's generation process and its directional asymmetry.&lt;/p&gt;

&lt;p&gt;The theory is broader than text. It provides a unified framework for autoregressive generative models, ranging from Transformers to Kalman filters.&lt;/p&gt;

&lt;p&gt;There is a technical obstacle: the next output can depend on a long history, not just the immediately previous output. That makes the observed process non-Markovian. Trying to enumerate every possible history would quickly become impractical.&lt;/p&gt;

&lt;p&gt;Sagawa's framework shows how to estimate entropy production efficiently without enumerating all those histories. It also decomposes entropy production into non-negative contributions at each timestep, using an information-theoretic perspective: inferring the past from the future.&lt;/p&gt;

&lt;p&gt;I find that reversal of viewpoint appealing. We normally discuss these models as predictors of what comes next; this theory also asks what looking backward can reveal.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the language-model experiments suggest
&lt;/h2&gt;

&lt;p&gt;The experiments used GPT-2 (124M) and Qwen3-4B-Base. Texts describing sequential events tended to have larger sentence-level entropy production than texts listing independent facts. In other words, reversed generation was relatively less likely for the sequential-event texts.&lt;/p&gt;

&lt;p&gt;That suggests the models' generation probabilities reflect something about event order. It offers a quantitative probe for investigating what is often called a model's internal “world model.”&lt;/p&gt;

&lt;p&gt;It does &lt;strong&gt;not&lt;/strong&gt; establish that an LLM understands causality in the same way a person does.&lt;/p&gt;

&lt;p&gt;There is also an important dataset caveat: the evaluation texts were generated by prompting commercial generative AI. Their construction could introduce features that matter to the comparison. The press release explicitly calls for further verification, including text sets constructed from theoretical definitions of order and causal relationships.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would take back to an app project
&lt;/h2&gt;

&lt;p&gt;In my RAG demo, making sources visible helps a reader inspect where an answer came from. It does not, by itself, establish that the answer describes events in a sensible sequence. Those are separate evaluation questions.&lt;/p&gt;

&lt;p&gt;This paper does not give me a ready-made accuracy score or a proven hallucination detector. I have not tested its measurement in my own apps.&lt;/p&gt;

&lt;p&gt;What it gives me is a sharper question: instead of only asking whether a generated explanation sounds good, what changes when I perturb its event order?&lt;/p&gt;

&lt;p&gt;For me, that is the interesting bridge between theory and building. “Does this model represent the world?” is enormous. Choosing a controlled reversal and studying its probability makes one part of that question more concrete.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;University of Tokyo press release (November 6, 2026): &lt;a href="https://www.t.u-tokyo.ac.jp/press/pr2026-11-06-001" rel="noopener noreferrer"&gt;https://www.t.u-tokyo.ac.jp/press/pr2026-11-06-001&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Takahiro Sagawa, &lt;em&gt;Stochastic Thermodynamics for Autoregressive Generative Models: A Non-Markovian Perspective&lt;/em&gt;, PRX Intelligence. DOI: 10.1103/tv38-b23y: &lt;a href="https://doi.org/10.1103/tv38-b23y" rel="noopener noreferrer"&gt;https://doi.org/10.1103/tv38-b23y&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>computerscience</category>
      <category>llm</category>
    </item>
    <item>
      <title>I Built a Japanese PDF RAG Demo Where You Can See What the Model Looked At</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Fri, 06 Nov 2026 17:57:20 +0000</pubDate>
      <link>https://dev.to/koheip/i-built-a-japanese-pdf-rag-demo-where-you-can-see-what-the-model-looked-at-2m1d</link>
      <guid>https://dev.to/koheip/i-built-a-japanese-pdf-rag-demo-where-you-can-see-what-the-model-looked-at-2m1d</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally published in Japanese on &lt;a href="https://zenn.dev/koheip/articles/rag-visible-sources" rel="noopener noreferrer"&gt;Zenn&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Hi, I'm Kohei Matsunobe, a second-year student in the online (correspondence) program at ZEN University. I'm working toward becoming an AI engineer, and I learn by building LLM-related systems with my own hands.&lt;/p&gt;

&lt;p&gt;When you ask an LLM about a document, you usually get back an answer in fluent, plausible language. What bothered me was the question: "Which part of the document is that answer actually based on?" I didn't want to judge an answer by whether it &lt;em&gt;sounded&lt;/em&gt; right. I wanted to build something where &lt;strong&gt;it's clear what the model looked at&lt;/strong&gt; when it answered.&lt;/p&gt;

&lt;p&gt;So I built a RAG demo: you upload PDFs, ask questions in Japanese, and get answers &lt;strong&gt;with sources (file name and page number)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/koheip/rag-doc-qa" rel="noopener noreferrer"&gt;https://github.com/koheip/rag-doc-qa&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This post isn't a usage guide. Instead, it focuses on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What I decided, and where, in order to show sources accurately&lt;/li&gt;
&lt;li&gt;What I learned once I evaluated it and looked at the numbers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Setup instructions are in the README, so please check there.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I built
&lt;/h2&gt;

&lt;p&gt;It's a Streamlit app. You register PDFs and ask a question; it searches for relevant passages and answers using only those passages as evidence. Answers carry numbers like [1], and each number maps to "file name p.page". You can also see the retrieved chunks and their similarity scores in the UI.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieval: &lt;code&gt;multilingual-e5-small&lt;/code&gt; + FAISS (&lt;code&gt;IndexFlatIP&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Generation: Google Gemini (official SDK &lt;code&gt;google-genai&lt;/code&gt;). The default is &lt;code&gt;gemini-3.5-flash-lite&lt;/code&gt;, and you can switch to &lt;code&gt;gemini-3.8-flash&lt;/code&gt; from the sidebar&lt;/li&gt;
&lt;li&gt;Without an API key, it runs in "extractive mode," which shows the retrieved passages as-is&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's the flow:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    A[PDF] --&amp;gt;|pypdf| B[Text per page]
    B --&amp;gt;|Japanese-aware chunking| C[Chunks]
    C --&amp;gt;|"passage: " + e5| D[(FAISS)]
    Q[Question] --&amp;gt;|"query: " + e5| D
    D --&amp;gt; R[top-k chunks + sources]
    R --&amp;gt;|with key| L[Answer with Gemini]
    R --&amp;gt;|no key| E[Extractive mode]&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;
  
  
  Decision 1: Chunks never cross page boundaries
&lt;/h2&gt;

&lt;p&gt;The decision that mattered most for showing accurate page numbers was how I split text into chunks.&lt;/p&gt;

&lt;p&gt;I wrote the chunker myself instead of using a library. Japanese has no spaces between words, so I measure length in &lt;strong&gt;characters&lt;/strong&gt;. Then I split into roughly 200-character pieces, &lt;strong&gt;preferring sentence boundaries&lt;/strong&gt; like 「。」, and overlap a bit of the previous chunk's tail so context isn't cut off at the seams.&lt;/p&gt;

&lt;p&gt;And &lt;strong&gt;chunks never cross pages&lt;/strong&gt;. If a chunk spans two pages, you can't say which single page it came from. Since the whole point of the app is showing sources, I prioritized citation accuracy over retrieval convenience here.&lt;/p&gt;

&lt;p&gt;I wrote it myself because I wanted Japanese-specific splitting in a form I could actually explain. If you leave it to a library, it's harder to explain in your own words why the text was cut where it was.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decision 2: Make it say "I don't know," and cite only what it used
&lt;/h2&gt;

&lt;p&gt;In the generation prompt, I number the retrieved chunks, attach their sources, and give instructions like this (from &lt;a href="https://github.com/koheip/rag-doc-qa/blob/main/src/llm.py" rel="noopener noreferrer"&gt;src/llm.py&lt;/a&gt;; the prompt itself is in Japanese):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;SYSTEM_PROMPT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;あなたは社内ドキュメントに関する質問に答えるアシスタントです。
以下のルールを必ず守ってください。
1. 回答は【参考資料】に書かれている内容だけを根拠にしてください。あなた自身の知識で補ってはいけません。
2. 【参考資料】に答えが書かれていない場合は、推測せずに「わからない」とだけ答えてください（この場合は資料番号を付けないでください）。
3. 回答の文末には、根拠にした資料の番号を [1] [2] のように付けてください。
4. 日本語で、簡潔かつ丁寧に答えてください。&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Roughly translated, the rules are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Base your answer only on the provided reference material; don't fill in with your own knowledge.&lt;/li&gt;
&lt;li&gt;If the answer isn't in the material, don't guess — just say 「わからない」 ("I don't know"), with no reference numbers.&lt;/li&gt;
&lt;li&gt;End the answer with the numbers of the passages you relied on, like [1] [2].&lt;/li&gt;
&lt;li&gt;Answer in Japanese, concisely and politely.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The key point is that &lt;strong&gt;I don't list every retrieved chunk as a "source." Only the numbers the answer actually references are shown as sources.&lt;/strong&gt; Even if the top 4 chunks are passed in, if the answer used just one, only one source is shown. When the answer is 「わからない」, no sources are shown.&lt;/p&gt;

&lt;p&gt;Temperature is set to 0.1, because I wanted answers that stay faithful to the material and don't wobble between runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decision 3: Let people try it without an API key
&lt;/h2&gt;

&lt;p&gt;Without an API key, the app runs in "extractive mode," showing the top chunks directly as the answer.&lt;/p&gt;

&lt;p&gt;I added this so anyone could try it right away, but once I built it I found another benefit. Extractive mode is &lt;strong&gt;retrieval only&lt;/strong&gt;, so before generation even happens, you can check whether the right passages were found at all. When the RAG answer is off, it became much easier to tell whether the problem is in retrieval or in generation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other choices
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Item&lt;/th&gt;
&lt;th&gt;Choice&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;UI&lt;/td&gt;
&lt;td&gt;Streamlit&lt;/td&gt;
&lt;td&gt;Python only; chat UI and file upload in a small amount of code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PDF loading&lt;/td&gt;
&lt;td&gt;pypdf&lt;/td&gt;
&lt;td&gt;Pure Python with few dependencies; behaves the same on Windows/Mac/Linux&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Embeddings&lt;/td&gt;
&lt;td&gt;multilingual-e5-small&lt;/td&gt;
&lt;td&gt;Free, runs locally, supports Japanese. About 470MB and fast enough on CPU&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vector store&lt;/td&gt;
&lt;td&gt;FAISS (IndexFlatIP)&lt;/td&gt;
&lt;td&gt;Shows how to use a library that's standard in practice, and the index can be swapped as data grows&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LLM&lt;/td&gt;
&lt;td&gt;Gemini (google-genai)&lt;/td&gt;
&lt;td&gt;Has a free tier and can be called in a few lines with the official SDK&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;E5 expects a &lt;code&gt;passage:&lt;/code&gt; prefix on documents and a &lt;code&gt;query:&lt;/code&gt; prefix on questions, so I follow that. Vectors are 384-dimensional and normalized to length 1, so FAISS's inner product is exactly cosine similarity.&lt;/p&gt;

&lt;p&gt;At this data size, a numpy matrix multiplication would be plenty. But with FAISS, when data grows I can swap the brute-force &lt;code&gt;IndexFlatIP&lt;/code&gt; for an approximate index. The vector store is isolated in one file, so I can change it without affecting the rest.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the evaluation taught me
&lt;/h2&gt;

&lt;p&gt;I didn't want to stop at "it kind of works," so I made retrieval and answers measurable. The results below are what I wrote up in the README on 2026-10-21.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Eval data: 30 questions on the bundled sample PDF (employment rules and an internal FAQ for a fictional company, 11 pages)&lt;/li&gt;
&lt;li&gt;Of the 30, 26 are answerable from the document and 4 are not. It also includes paraphrased questions that use different words from the document&lt;/li&gt;
&lt;li&gt;Retrieval is dense vector search (e5-small, top-k=4)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Retrieval: Hit@3 is high, Hit@1 is still low
&lt;/h3&gt;

&lt;p&gt;With a chunk size of 200 characters (the one I adopted), retrieval on the 26 answerable questions looked like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hit@1&lt;/td&gt;
&lt;td&gt;73.1%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hit@3&lt;/td&gt;
&lt;td&gt;96.2%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Recall@4&lt;/td&gt;
&lt;td&gt;100.0%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MRR&lt;/td&gt;
&lt;td&gt;0.856&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hit@3 on paraphrased questions&lt;/td&gt;
&lt;td&gt;92.3%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every correct passage is within the top 4, but it's ranked first only 73.1% of the time. In other words, the right answer often lands at rank 2–4.&lt;/p&gt;

&lt;p&gt;Right now I pass the top 4 chunks to the LLM together, so this doesn't affect the answers. But if I want to pass fewer chunks to lower cost, Hit@1 needs to improve. The clearest thing the numbers showed me was that "the answer is correct" and "retrieval is good enough" are two different things.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bigger chunks aren't automatically better
&lt;/h3&gt;

&lt;p&gt;I compared chunk sizes of 150, 200, 300, and 400 characters, and 200 gave the best balance. The surprise was 300: Hit@3 on paraphrased questions &lt;strong&gt;dropped from 92.3% to 69.2%&lt;/strong&gt;. My read is that one chunk ends up mixing several rules (articles), so the meaning of the vector gets blurry.&lt;/p&gt;

&lt;p&gt;If I had chosen the size based only on the intuition that "more context should be better," I would have missed this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Generation: this dataset doesn't separate models
&lt;/h3&gt;

&lt;p&gt;With &lt;code&gt;gemini-3.5-flash-lite&lt;/code&gt; (the default), all 26 answerable questions were answered correctly (26/26), and all 4 unanswerable questions were correctly refused with 「わからない」 (4/4). Latency was 0.56s at p50 and 0.72s at p95. Grading was done by a different LLM than the answering model, comparing each answer with a reference answer and scoring it 0/1 (LLM-as-a-judge).&lt;/p&gt;

&lt;p&gt;I don't read this as "the model is perfect." I read it as &lt;strong&gt;the current dataset is too easy and has hit the ceiling&lt;/strong&gt;. To see differences, I need harder questions — ones that span multiple passages, or that require calculation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Limits of this evaluation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;30 questions is small; a single question moves the score by about 4 points&lt;/li&gt;
&lt;li&gt;Both the dataset and the grading come from one person (me) and one LLM&lt;/li&gt;
&lt;li&gt;I also tried comparing against &lt;code&gt;gemini-3.8-flash&lt;/code&gt;, but it was under heavy load (503) during evaluation and didn't respond, so I couldn't compare&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Known limitations
&lt;/h2&gt;

&lt;p&gt;Here are the limits of this demo that I found while building it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;E5 similarity scores tend to cluster around 0.8–0.9&lt;/strong&gt;, so it's hard to set a threshold like "below X means unrelated." That's why, for questions not covered by the document, I leave the decision to the LLM via the prompt and have it say 「わからない」&lt;/li&gt;
&lt;li&gt;With paraphrases like 給料 vs. 給与 (both meaning "salary"), the correct passage sometimes isn't ranked first&lt;/li&gt;
&lt;li&gt;Scanned-image-only PDFs need OCR, so they're not supported&lt;/li&gt;
&lt;li&gt;The index lives only in memory and disappears when the session ends (I prioritized simplicity for a demo)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tests
&lt;/h2&gt;

&lt;p&gt;Tests are written with pytest and cover chunking, retrieval, the LLM-related logic, and the evaluation metrics. Retrieval tests use a lightweight fake embedder built from character counts (FakeEmbedder), and generation tests use a fake LLM (FakeLLM), so you can check the main flow &lt;strong&gt;without downloading the model and without calling the API&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next: hybrid search
&lt;/h2&gt;

&lt;p&gt;To improve Hit@1, my next step is hybrid search that combines BM25 (keyword search) with vector search. Keyword search is better at proper nouns, numbers, and article numbers, so the idea is to pair it with vector search, which handles paraphrases better.&lt;/p&gt;

&lt;p&gt;I haven't implemented it yet. I've made the retrieval method swappable and prepared the function specs and tests for &lt;code&gt;src/bm25.py&lt;/code&gt; first. I plan to measure whether Hit@1 and MRR go up on the same 30 questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;To show accurate page numbers, chunks never cross pages, and I wrote my own Japanese-aware chunker&lt;/li&gt;
&lt;li&gt;Only the numbers the answer actually references are shown as sources, and when the document doesn't cover the question, the model says 「わからない」&lt;/li&gt;
&lt;li&gt;In evaluation, Hit@3 was 96.2% but Hit@1 was 73.1%. Widening chunks to 300 characters dropped paraphrase Hit@3 from 92.3% to 69.2%&lt;/li&gt;
&lt;li&gt;"The answer is correct" and "retrieval is good enough" are different things, and I only saw what to do next once I put numbers on it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When building RAG, I found it helps to be able to check "what did it look at to answer?" both in the UI and in numbers, not just how the answer looks. All the code is public, so feel free to try it out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/koheip/rag-doc-qa" rel="noopener noreferrer"&gt;https://github.com/koheip/rag-doc-qa&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rag</category>
      <category>gemini</category>
      <category>python</category>
      <category>llm</category>
    </item>
    <item>
      <title>What I Thought About Before Putting a Generative-AI Shrine Guide in My Indie iOS App (API Gateway + Lambda + Gemini, Consent and Privacy)</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Fri, 06 Nov 2026 17:57:15 +0000</pubDate>
      <link>https://dev.to/koheip/what-i-thought-about-before-putting-a-generative-ai-shrine-guide-in-my-indie-ios-app-api-gateway--2g4i</link>
      <guid>https://dev.to/koheip/what-i-thought-about-before-putting-a-generative-ai-shrine-guide-in-my-indie-ios-app-api-gateway--2g4i</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally published in Japanese on &lt;a href="https://qiita.com/koheip/items/ae6963c09cd4c4f60a48" rel="noopener noreferrer"&gt;Qiita&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Hi, I'm Kohei Matsunobe. I'm a second-year student in the online (correspondence) program at ZEN University, studying to become an AI engineer.&lt;/p&gt;

&lt;p&gt;On my own, I build an iOS app called &lt;a href="https://apps.apple.com/jp/app/%E3%82%AB%E3%83%9F%E3%82%81%E3%81%90/id6821107881" rel="noopener noreferrer"&gt;KamiMeg (カミメグ)&lt;/a&gt;. It's a digital &lt;em&gt;goshuin&lt;/em&gt; book: you take photos of the &lt;em&gt;goshuin&lt;/em&gt; (the calligraphy stamps you receive at Japanese shrines), find shrines nearby, and keep a record of your visits. It's free, there's no account, and your records are stored on your device.&lt;/p&gt;

&lt;p&gt;I released v1.0 in October 2026 and v1.1.0 in November 2026. The headline feature of v1.1.0 is a generative-AI feature where &lt;strong&gt;a "companion deity" introduces the shrine to you when you press a button&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This post is about what I thought through before shipping that feature. It's not a code walkthrough; it's about three decisions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Where the API key should live (and why I went serverless)&lt;/li&gt;
&lt;li&gt;How to keep the app's promise — "your records stay on your device" — even after adding AI&lt;/li&gt;
&lt;li&gt;Why I ended up with Gemini, even though I first looked at Bedrock and the Claude API&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  KamiMeg before the AI feature
&lt;/h2&gt;

&lt;p&gt;Originally, KamiMeg was an app that did almost everything on the device.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;th&gt;What I use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;App&lt;/td&gt;
&lt;td&gt;Expo / React Native (TypeScript)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Storing records&lt;/td&gt;
&lt;td&gt;SQLite (on device)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Finding nearby shrines&lt;/td&gt;
&lt;td&gt;Google Places API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ads&lt;/td&gt;
&lt;td&gt;Google AdMob&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;There was no backend server of my own and no account. "Your &lt;em&gt;goshuin&lt;/em&gt; photos and visit records live only on your own device" was something I really cared about as the person building it.&lt;/p&gt;

&lt;p&gt;When I submitted v1.0, App Store review needed some extra back-and-forth. I responded, it passed, and the app went live — but it taught me that even as an indie developer, once you ship to a store, you should build things you can explain. That became a starting assumption when I designed the AI feature.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I wanted to build
&lt;/h2&gt;

&lt;p&gt;When you're looking for shrines and logging visits, there are moments where you wonder, "What kind of place is this shrine?" So I thought it would be fun to show a short introduction for each shrine. Just showing a plain description felt a bit flat, though, so in the app it's the "companion deity" who introduces the shrine.&lt;/p&gt;

&lt;p&gt;The introduction is never generated automatically. It's generated &lt;strong&gt;only when the user presses the button&lt;/strong&gt;. I'll explain why in the privacy section.&lt;/p&gt;

&lt;p&gt;In v1.1.0 I also made it so that when you search for a shrine by name, only that shrine is shown, and I unified the app's display name as "カミメグ".&lt;/p&gt;

&lt;h2&gt;
  
  
  Decision 1: Don't put the API key in the app (API Gateway → Lambda → Gemini)
&lt;/h2&gt;

&lt;p&gt;The simplest way to use a generative-AI API from an app is to call it directly from the app. But that means shipping the API key inside the app. A key inside an app binary can be extracted, and since I manage the spending cap myself as an indie developer, I wanted to avoid that.&lt;/p&gt;

&lt;p&gt;So I put a thin AWS serverless layer between the app and the AI.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    A[iOS app&amp;lt;br/&amp;gt;KamiMeg] --&amp;gt;|Shrine name &amp;amp; address&amp;lt;br/&amp;gt;after consent only| B[Amazon API Gateway]
    B --&amp;gt; C[AWS Lambda]
    C --&amp;gt; D[Google Gemini API]
    D --&amp;gt; C
    C --&amp;gt; B
    B --&amp;gt;|Introduction text| A&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The flow is simple: app → Amazon API Gateway → AWS Lambda → Google Gemini API. The Gemini API key lives only on the server side; the app never has it.&lt;/p&gt;

&lt;p&gt;Why serverless:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;I didn't want an always-on server.&lt;/strong&gt; Introductions are generated only when the button is pressed, so it's enough for something to run only when a request comes in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I can swap what's behind it without changing the app.&lt;/strong&gt; The app only talks to API Gateway, so which AI the Lambda calls can change without an app update. This turned out to matter a lot when I switched to Gemini (more on that below).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;I can enforce usage limits on the server.&lt;/strong&gt; A daily usage limit can live on the server side (see below).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Decision 2: Don't break the "records stay on your device" promise
&lt;/h2&gt;

&lt;p&gt;Adding an AI feature means sending &lt;em&gt;something&lt;/em&gt; off the device. KamiMeg's selling point is "no account, records on device," so this is where I was most careful.&lt;/p&gt;

&lt;p&gt;Here are the rules I settled on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Only the shrine name and address are sent.&lt;/strong&gt; That's the minimum needed to write an introduction.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;They're sent only after the user consents.&lt;/strong&gt; Without consent, the AI feature isn't used.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Goshuin photos, visit records, and location are not sent.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No account.&lt;/strong&gt; I don't ask users to log in for the AI feature either.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;There's a daily usage limit.&lt;/strong&gt; It's tracked with a random per-device ID, which isn't information that identifies a person.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generated introductions may be stored on the developer's server for up to 90 days.&lt;/strong&gt; This is stated explicitly in the privacy policy (PRIVACY.md).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;"Generate only when the button is pressed" is part of these rules too. I didn't want a behavior where just opening a screen silently sends data somewhere. Data that the user agreed to share is sent only when they press the button themselves. I think that's easier to explain, and it's more reassuring for the people using the app.&lt;/p&gt;

&lt;p&gt;The usage limit also protects my costs. In indie development, if an API keeps getting called unexpectedly, that bill is on me. Being able to hold the limit on the server is another reason I'm glad the app doesn't call the API directly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decision 3: Why Gemini
&lt;/h2&gt;

&lt;p&gt;To be honest, I didn't decide on Gemini from the start. At first I also considered &lt;strong&gt;Amazon Bedrock&lt;/strong&gt; and the &lt;strong&gt;Claude API&lt;/strong&gt; as candidates.&lt;/p&gt;

&lt;p&gt;But once I actually moved forward, I found that usage limits and payment conditions didn't fit my situation as an indie developer, and I couldn't take it to production as-is. So I switched to the &lt;strong&gt;Gemini API&lt;/strong&gt;, finished the feature, and shipped it to production.&lt;/p&gt;

&lt;p&gt;This is where Decision 1 saved me. Because the app only knows about API Gateway, changing which AI gets called was a matter inside the Lambda. Leaving room to change "which AI to use" later is, I think, the reason the switch didn't stall the release.&lt;/p&gt;

&lt;p&gt;The lesson I took from this: &lt;strong&gt;before comparing model quality, check early whether you can actually use the service in production from your own position.&lt;/strong&gt; Limits and payment conditions are hard to see when you just call an API a few times to try it out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decide what you won't publish
&lt;/h2&gt;

&lt;p&gt;When releasing the app and writing about it, I also decided what &lt;em&gt;not&lt;/em&gt; to publish: the API endpoint URL, the app's key, the AWS account and region, and specific numbers for usage limits. None of them appear in this post.&lt;/p&gt;

&lt;p&gt;Showing the flow "API Gateway → Lambda → Gemini" in a diagram is fine for explaining how it works. Concrete endpoints and limit values, on the other hand, could become clues for abuse. As an indie developer you sometimes feel like making everything open, but this is where I draw the line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats and what's next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;AI-generated introductions aren't guaranteed to be accurate. As the builder, I see them as an "entry point," and I think it's best to check the details with the shrine's official information.&lt;/li&gt;
&lt;li&gt;Because introductions are generated through the server, the feature assumes the user has consented and is online.&lt;/li&gt;
&lt;li&gt;Going forward, I want to keep adding features without breaking the app's promises: no account, records stay on the device.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I didn't call the generative-AI API directly from the app. A serverless setup — API Gateway → Lambda → Gemini — keeps the key and the usage limit on the server.&lt;/li&gt;
&lt;li&gt;Only the shrine name and address are sent, and only after consent. Photos, records, and location are not sent, and there's no account.&lt;/li&gt;
&lt;li&gt;I considered Bedrock and the Claude API, but switched to Gemini because of limits and payment conditions. Since the app doesn't know what's behind the API, the switch didn't stop the release.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you put generative AI into an app, I found it pays off to decide "what you send and what you don't" and "whether you can swap it later" before picking a model. I hope this is useful for anyone else building apps on their own.&lt;/p&gt;

&lt;p&gt;KamiMeg is available on the App Store (Japanese). If you like visiting shrines, give it a try:&lt;br&gt;
&lt;a href="https://apps.apple.com/jp/app/%E3%82%AB%E3%83%9F%E3%82%81%E3%81%90/id6821107881" rel="noopener noreferrer"&gt;https://apps.apple.com/jp/app/カミめぐ/id6821107881&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>gemini</category>
      <category>reactnative</category>
      <category>ios</category>
    </item>
    <item>
      <title>Before You Burn GPU Hours, Smoke-Test One Task on a Cheap CPU Runtime</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Sat, 31 Oct 2026 07:34:56 +0000</pubDate>
      <link>https://dev.to/koheip/before-you-burn-gpu-hours-smoke-test-one-task-on-a-cheap-cpu-runtime-h8h</link>
      <guid>https://dev.to/koheip/before-you-burn-gpu-hours-smoke-test-one-task-on-a-cheap-cpu-runtime-h8h</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally published in Japanese on &lt;a href="https://zenn.dev/koheip/articles/cheap-runtime-smoke-test" rel="noopener noreferrer"&gt;Zenn&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Hi, I'm Kohei Matsunobe, a second-year student in the online (correspondence) program at ZEN University. I'm working toward becoming an AI engineer, and on my own I run experiment pipelines that evaluate LLM outputs and code on notebooks and cloud runtimes.&lt;/p&gt;

&lt;p&gt;GPU runtimes are great, but they're expensive per hour, and there's a cap on how many compute units you can use. I've made the same mistakes more than once: "I grabbed a GPU, launched the real job, and it crashed in the first few minutes," or "it crashed, I didn't notice, and the runtime just sat there running."&lt;/p&gt;

&lt;p&gt;Looking back, almost all of those failures could have been caught without a GPU. In this post, I'll walk through the idea of a "smoke test" — a minimal check you run on a cheap CPU runtime before moving up to the expensive one — plus a small script you can use right away.&lt;/p&gt;

&lt;h2&gt;
  
  
  What tends to go wrong
&lt;/h2&gt;

&lt;p&gt;In pipelines that evaluate LLMs or generated code, these problems come up a lot:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Missing test dependencies&lt;/strong&gt;: Your setup grades generated code with pytest, but the production runtime doesn't have pytest, or the libraries the tested code needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache or data not found&lt;/strong&gt;: The path where you thought you'd put model weights or dataset caches is empty on the fresh runtime. So downloads run every time, or you get errors because offline mode is still on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mismatched environment variables or paths&lt;/strong&gt;: It worked locally, but on a different runtime the working directory or cache location has changed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An exception on the very first task&lt;/strong&gt;: Simple mistakes, like a missing output directory or a misspelled argument name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these have anything to do with GPU performance. But when they happen on a GPU runtime, you lose all the time spent on setup and model loading too. Retry the job enough times and you might suddenly find you've used up your compute units.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea behind the smoke test
&lt;/h2&gt;

&lt;p&gt;It boils down to three points:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Keep dependencies identical to production&lt;/strong&gt;: Build the environment from the same definition as production — the same requirements file, lock file, or container image. If you maintain a separate dependency list for CPU, you hide the very differences you want to catch. (The only exception: packages that need a GPU-specific build get handled separately.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run just one task on the cheap runtime&lt;/strong&gt;: Don't run the whole eval set — just one item. Inference may be slow on CPU, but all you need to know is "does it make it to the end?"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Promote to the expensive runtime only if it passes&lt;/strong&gt;: Only when the smoke test succeeds do you run the real job on the GPU runtime, with the same code and the same config.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you think of it as a CI pipeline, it's a staged gate: put a light job in front of the heavy one, and don't move on unless the light one passes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The minimum checklist
&lt;/h2&gt;

&lt;p&gt;Here's what I check every time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can the key packages be imported? (Including pytest for evaluation)&lt;/li&gt;
&lt;li&gt;Do the cache and data directories exist, and are they non-empty?&lt;/li&gt;
&lt;li&gt;Are the required environment variables set?&lt;/li&gt;
&lt;li&gt;Can I write to the output directory?&lt;/li&gt;
&lt;li&gt;Does at least one pytest test actually pass?&lt;/li&gt;
&lt;li&gt;Can the same entry point as production run to completion as a dry run with just one task?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You don't need to do all of these perfectly. Just adding "anything that has bitten me even once" to the list goes a long way.&lt;/p&gt;

&lt;h2&gt;
  
  
  A small script
&lt;/h2&gt;

&lt;p&gt;Here's a script that bundles the checks above. Adjust &lt;code&gt;REQUIRED_MODULES&lt;/code&gt;, &lt;code&gt;REQUIRED_PATHS&lt;/code&gt;, and &lt;code&gt;run_task&lt;/code&gt; to fit your own pipeline.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;#!/usr/bin/env python3
# smoke_test.py
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Smoke test to run on a cheap runtime before moving to an expensive one.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;__future__&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;annotations&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;importlib&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;

&lt;span class="c1"&gt;# Modules to verify with the same dependency stack as production
&lt;/span&gt;&lt;span class="n"&gt;REQUIRED_MODULES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;numpy&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pytest&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;transformers&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;# Cache/data paths that should exist and have contents
&lt;/span&gt;&lt;span class="n"&gt;REQUIRED_PATHS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;HF_HOME&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;~/.cache/huggingface&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;expanduser&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;REQUIRED_ENV&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;HF_HOME&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check_imports&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="n"&gt;errors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;importlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;import_module&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# also catch init errors, not just ImportError
&lt;/span&gt;            &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;import failed: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check_paths&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="n"&gt;errors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
            &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;path missing: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_dir&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nf"&gt;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;iterdir&lt;/span&gt;&lt;span class="p"&gt;()):&lt;/span&gt;
            &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;directory is empty: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check_env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;env var not set: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check_writable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out_dir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;out_dir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exist_ok&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;probe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;out_dir&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.smoke_write_test&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="n"&gt;probe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ok&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;probe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unlink&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;OSError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;not writable: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;out_dir&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;run_one_pytest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;test_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="c1"&gt;# e.g. tests/test_eval.py::test_single_case
&lt;/span&gt;    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;executable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-m&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pytest&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-q&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-x&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;test_id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="c1"&gt;# Exit code 5 means "no tests were collected", so treat it as a failure too
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;returncode&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pytest failed: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;test_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; (exit=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;returncode&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;load_tasks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;run_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Replace this with the same processing as production (inference, grading)
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ok&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ArgumentParser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cheap runtime smoke test&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--tasks&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;JSONL file, one task per line&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--out&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;outputs&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--pytest&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;metavar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TEST_ID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;run a single test ID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--dry-run&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;store_true&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;run only one task&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_args&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="n"&gt;errors&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;check_imports&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;REQUIRED_MODULES&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;errors&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;check_paths&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;REQUIRED_PATHS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;errors&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;check_env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;REQUIRED_ENV&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;errors&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;check_writable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pytest&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;errors&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;run_one_pytest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pytest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[NG] Pre-flight checks found problems:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  -&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;tasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_tasks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dry_run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;tasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;[:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;run_task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ensure_ascii&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[OK] Smoke test passed. Safe to promote to the expensive runtime.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the cheap CPU runtime, run it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python smoke_test.py &lt;span class="nt"&gt;--tasks&lt;/span&gt; data/tasks.jsonl &lt;span class="nt"&gt;--dry-run&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--pytest&lt;/span&gt; tests/test_eval.py::test_single_case
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you only start the real run when the exit code is 0, the same pattern works in notebooks and in CI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python smoke_test.py &lt;span class="nt"&gt;--tasks&lt;/span&gt; data/tasks.jsonl &lt;span class="nt"&gt;--dry-run&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; python run_full_eval.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Most expensive GPU job failures come from things that have nothing to do with the GPU: dependencies, caches, and path settings.&lt;/li&gt;
&lt;li&gt;Keep the same dependency stack as production, push just one task through on a cheap CPU runtime, and promote to the expensive runtime only when it passes.&lt;/li&gt;
&lt;li&gt;For the checklist, adding things you've personally been bitten by, little by little, is plenty.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A few minutes of smoke testing protects both your compute units and your motivation. I hope this helps anyone else running experiments on their own!&lt;/p&gt;

</description>
      <category>python</category>
      <category>testing</category>
      <category>pytest</category>
      <category>mlops</category>
    </item>
    <item>
      <title>Summarize Kaggle Notebook Status and Logs in ~7 Lines with the Kaggle CLI (Goodbye, .bat + Notepad)</title>
      <dc:creator>kohei matsunobu</dc:creator>
      <pubDate>Sat, 31 Oct 2026 07:34:55 +0000</pubDate>
      <link>https://dev.to/koheip/summarize-kaggle-notebook-status-and-logs-in-7-lines-with-the-kaggle-cli-goodbye-bat-notepad-32o2</link>
      <guid>https://dev.to/koheip/summarize-kaggle-notebook-status-and-logs-in-7-lines-with-the-kaggle-cli-goodbye-bat-notepad-32o2</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally published in Japanese on &lt;a href="https://qiita.com/koheip/items/2b2ea56bbedd5b648055" rel="noopener noreferrer"&gt;Qiita&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Hi, I'm Kohei Matsunobe. I'm a second-year student in the online (correspondence) program at ZEN University, studying to become an AI engineer.&lt;/p&gt;

&lt;p&gt;Once I started running Kaggle notebooks (kernels) from my local machine with &lt;code&gt;kaggle kernels push&lt;/code&gt;, one small thing kept eating my time: &lt;strong&gt;checking what was going on.&lt;/strong&gt; Is it still running? Did it finish? Did it fail? And if it failed, where? Checking that in the browser or digging through log files every single time got old fast.&lt;/p&gt;

&lt;p&gt;In this post, I'll share a script that calls &lt;code&gt;kaggle kernels status&lt;/code&gt; and &lt;code&gt;kaggle kernels output&lt;/code&gt; from Python and boils the status and log down to &lt;strong&gt;a ~7-line summary plus one CSV row&lt;/strong&gt;. I'll also cover how I fixed garbled text (mojibake) on Windows, and how I made the same script usable both from a &lt;code&gt;.bat&lt;/code&gt; file and from an AI agent.&lt;/p&gt;

&lt;p&gt;Note: this post is not about submissions. It focuses purely on &lt;strong&gt;monitoring run status and summarizing logs&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I used to do it
&lt;/h2&gt;

&lt;p&gt;At first, I got by with a batch file like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;@echo &lt;span class="na"&gt;off&lt;/span&gt;
&lt;span class="kd"&gt;kaggle&lt;/span&gt; &lt;span class="kd"&gt;kernels&lt;/span&gt; &lt;span class="kd"&gt;status&lt;/span&gt; &lt;span class="kd"&gt;koheip&lt;/span&gt;&lt;span class="na"&gt;/my-notebook
&lt;/span&gt;&lt;span class="kd"&gt;kaggle&lt;/span&gt; &lt;span class="kd"&gt;kernels&lt;/span&gt; &lt;span class="kd"&gt;output&lt;/span&gt; &lt;span class="kd"&gt;koheip&lt;/span&gt;&lt;span class="na"&gt;/my-notebook -p &lt;/span&gt;.\out &lt;span class="na"&gt;-o
&lt;/span&gt;&lt;span class="kd"&gt;notepad&lt;/span&gt; .\out\my&lt;span class="na"&gt;-notebook&lt;/span&gt;.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It worked, but it had a few problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The logs are long, and scrolling through Notepad to find the error is painful&lt;/li&gt;
&lt;li&gt;Non-ASCII output (Japanese, in my case) got garbled in the console&lt;/li&gt;
&lt;li&gt;There was no record of "when, which notebook, and what status"&lt;/li&gt;
&lt;li&gt;When I asked an AI agent to check the log, it had to read the entire thing, which is wasteful&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last point was the big one. If you're handing something to an agent, &lt;strong&gt;a short text with only the information you need&lt;/strong&gt; is much easier to work with.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the CLI gives you
&lt;/h2&gt;

&lt;p&gt;You only need two commands (official docs: &lt;a href="https://github.com/Kaggle/kaggle-api/blob/main/docs/kernels.md" rel="noopener noreferrer"&gt;Kaggle CLI documentation&lt;/a&gt;, &lt;a href="https://www.kaggle.com/docs/api" rel="noopener noreferrer"&gt;kaggle.com/docs/api&lt;/a&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;kaggle kernels status&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Shows the status of the latest run. You pass the kernel as &lt;code&gt;owner/kernel-slug&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;kaggle&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;kernels&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;koheip/my-notebook&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output is a single line (on failure, an extra &lt;code&gt;Failure message: "..."&lt;/code&gt; line is added):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;koheip/my-notebook has status "KernelWorkerStatus.COMPLETE"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Depending on the CLI version, you may see lowercase &lt;code&gt;complete&lt;/code&gt; or the &lt;code&gt;KernelWorkerStatus.&lt;/code&gt; prefix, so the script &lt;strong&gt;takes only the last word and lowercases it&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;kaggle kernels output&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Downloads the output files from the latest run. The main options:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-p, --path&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Destination folder&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-o, --force&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Overwrite existing files&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-q, --quiet&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Suppress progress output&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;--file-pattern&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Only download files matching a regex&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The key point: along with the output files, it also saves &lt;strong&gt;the execution log as &lt;code&gt;&amp;lt;kernel-slug&amp;gt;.log&lt;/code&gt;&lt;/strong&gt;. In most cases, it's a JSON array of entries with &lt;code&gt;stream_name&lt;/code&gt; (stdout / stderr), &lt;code&gt;time&lt;/code&gt;, and &lt;code&gt;data&lt;/code&gt;. That's what we'll read and summarize.&lt;/p&gt;

&lt;p&gt;If your notebook produces large output files, narrowing things down with &lt;code&gt;--file-pattern&lt;/code&gt; speeds it up.&lt;/p&gt;

&lt;h3&gt;
  
  
  Authentication
&lt;/h3&gt;

&lt;p&gt;The Kaggle CLI can authenticate via the &lt;code&gt;KAGGLE_API_TOKEN&lt;/code&gt; environment variable, &lt;code&gt;~/.kaggle/access_token&lt;/code&gt;, or the classic &lt;code&gt;~/.kaggle/kaggle.json&lt;/code&gt;, among others. I went with &lt;strong&gt;reading the token from a dedicated file and passing it as an environment variable only to the child process&lt;/strong&gt;. That way, whether the script is called from a &lt;code&gt;.bat&lt;/code&gt; file or from an agent, the token is loaded the same way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The summary script
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;kaggle_status_summary.py&lt;/code&gt;. It only uses the standard library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# kaggle_status_summary.py
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;

&lt;span class="c1"&gt;# Force stdout to UTF-8, even on Windows (Python 3.7+)
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;hasattr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;reconfigure&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reconfigure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replace&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;DEFAULT_TOKEN_FILE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.config&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;kaggle_token.txt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;build_env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token_file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Read the token from a file and build env vars for the child process.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PYTHONIOENCODING&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PYTHONUTF8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;token_file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;KAGGLE_API_TOKEN&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;token_file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replace&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;returncode&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; failed: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stderr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;kaggle&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;kernels&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;has status &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;([^&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;]+)&lt;/span&gt;&lt;span class="sh"&gt;"'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;unknown&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Failure message: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;(.*)&lt;/span&gt;&lt;span class="sh"&gt;"'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;log_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]]:&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Return a list of (stream_name, text). Fall back to plain text if it isn&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;t JSON.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;log_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replace&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;stream_name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nf"&gt;except &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;JSONDecodeError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;AttributeError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;TypeError&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[(&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splitlines&lt;/span&gt;&lt;span class="p"&gt;()]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;ap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ArgumentParser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;kernel&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;help&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;owner/kernel-slug&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--out&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;kaggle_out&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;kaggle_status_log.csv&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--token-file&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;DEFAULT_TOKEN_FILE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_args&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;build_env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;token_file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;failure&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;slug&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;out_dir&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;slug&lt;/span&gt;
    &lt;span class="n"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;complete&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;error&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cancelacknowledged&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;out_dir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mkdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parents&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exist_ok&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;kaggle&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;kernels&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;output&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
             &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-p&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out_dir&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-o&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-q&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;out_dir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;iterdir&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_file&lt;/span&gt;&lt;span class="p"&gt;()]&lt;/span&gt;
        &lt;span class="n"&gt;log_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;out_dir&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.log&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;log_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
            &lt;span class="n"&gt;entries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;read_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;log_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;err_pat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;(Error|Exception|Traceback)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;stderr_n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;entries&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;stderr&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;err_lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;entries&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err_pat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
    &lt;span class="n"&gt;last_line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;reversed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()),&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%Y-%m-%d %H:%M:%S&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# The "~7 line" summary
&lt;/span&gt;    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[kernel]  &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[checked] &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[status]  &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; / &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;failure&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;failure&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[log]     &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; entries (stderr: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;stderr_n&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[errors]  &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err_lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; lines&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[last_err] &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;err_lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err_lines&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[tail]    &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;last_line&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;  / files: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Append one row to a CSV history (with BOM so Excel opens it cleanly)
&lt;/span&gt;    &lt;span class="n"&gt;csv_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;csv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;csv_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;csv_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newline&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8-sig&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;csv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writerow&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;checked_at&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;kernel&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;log_entries&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;stderr&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;error_lines&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;last_error&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;files&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writerow&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;stderr_n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err_lines&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;err_lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;][:&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err_lines&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;)])&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;error&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running it looks like this (values are just an example):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[kernel]  koheip/my-notebook
[checked] 2026-10-31 15:42:10
[status]  complete
[log]     214 entries (stderr: 12)
[errors]  0 lines
[last_err] -
[tail]    Done.  / files: 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things I was deliberate about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Exit code&lt;/strong&gt;: it returns 1 when the status is &lt;code&gt;error&lt;/code&gt;, so it's easy to branch on with &lt;code&gt;if errorlevel 1&lt;/code&gt; in a &lt;code&gt;.bat&lt;/code&gt; file or on the agent side&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Status normalization&lt;/strong&gt;: to absorb differences between CLI versions, &lt;code&gt;KernelWorkerStatus.COMPLETE&lt;/code&gt; becomes &lt;code&gt;complete&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No download while running&lt;/strong&gt;: for &lt;code&gt;running&lt;/code&gt; / &lt;code&gt;queued&lt;/code&gt;, it only checks the status and exits, so it stays lightweight even if you call it often&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That said, the Kaggle API has rate limits. If you monitor in a loop, leave a gap of a few minutes between checks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up the token file
&lt;/h3&gt;

&lt;p&gt;Generate a token on &lt;a href="https://www.kaggle.com/settings/api" rel="noopener noreferrer"&gt;your Kaggle settings page&lt;/a&gt; and save it as a one-line text file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c"&gt;# PowerShell: create the token file (it should contain only the token, on one line)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;New-Item&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-ItemType&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Directory&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Force&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="bp"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;\.config"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-Null&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nx"&gt;Set-Content&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="bp"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;\.config\kaggle_token.txt"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Value&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"YOUR_TOKEN_HERE"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ascii&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-NoNewline&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm strict about two rules: &lt;strong&gt;never put this file under Git&lt;/strong&gt;, and never paste it into an article or a chat. When an agent uses the script, all it needs is the script's path; it never has to see the token itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixing garbled text on Windows
&lt;/h2&gt;

&lt;p&gt;On Windows, the console code page often isn't UTF-8 by default (on Japanese Windows it's CP932 / Shift_JIS). Kaggle logs, on the other hand, are UTF-8. If you do nothing, non-ASCII characters get garbled, or the script dies with a &lt;code&gt;UnicodeEncodeError&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The fix is to switch to UTF-8 on &lt;strong&gt;both the console side and the Python side&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Calling from a .bat file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;@echo &lt;span class="na"&gt;off&lt;/span&gt;
&lt;span class="nb"&gt;chcp&lt;/span&gt; &lt;span class="m"&gt;65001&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kr"&gt;nul&lt;/span&gt;
&lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="kd"&gt;PYTHONIOENCODING&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kd"&gt;utf&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;
&lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="kd"&gt;PYTHONUTF8&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;
&lt;span class="kd"&gt;python&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="vm"&gt;%~dp0&lt;/span&gt;&lt;span class="s2"&gt;kaggle_status_summary.py"&lt;/span&gt; &lt;span class="kd"&gt;koheip&lt;/span&gt;&lt;span class="na"&gt;/my-notebook
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;errorlevel&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="err"&gt;!&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="kd"&gt;The&lt;/span&gt; &lt;span class="nb"&gt;run&lt;/span&gt; &lt;span class="kd"&gt;ended&lt;/span&gt; &lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="kd"&gt;an&lt;/span&gt; &lt;span class="kd"&gt;error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your &lt;code&gt;.bat&lt;/code&gt; file itself contains non-ASCII text, save it as UTF-8 so it displays correctly after &lt;code&gt;chcp 65001&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Calling from PowerShell
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;chcp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;65001&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;$null&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;]::&lt;/span&gt;&lt;span class="n"&gt;OutputEncoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;System.Text.Encoding&lt;/span&gt;&lt;span class="p"&gt;]::&lt;/span&gt;&lt;span class="n"&gt;UTF8&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nv"&gt;$OutputEncoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;System.Text.Encoding&lt;/span&gt;&lt;span class="p"&gt;]::&lt;/span&gt;&lt;span class="n"&gt;UTF8&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="nn"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;PYTHONIOENCODING&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"utf-8"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="nn"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;PYTHONUTF8&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="n"&gt;python&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;\kaggle_status_summary.py&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;koheip/my-notebook&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$LASTEXITCODE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-ne&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Write-Host&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"[!] The run ended with an error"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What the Python side does
&lt;/h3&gt;

&lt;p&gt;Inside the script, I also do three things just to be safe:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sys.stdout.reconfigure(encoding="utf-8")&lt;/code&gt; to make stdout UTF-8&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;subprocess.run(..., encoding="utf-8", errors="replace")&lt;/code&gt; to read the child process output as UTF-8&lt;/li&gt;
&lt;li&gt;Pass &lt;code&gt;PYTHONIOENCODING=utf-8&lt;/code&gt; to the child process (the Kaggle CLI) as well&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are cases where &lt;code&gt;chcp 65001&lt;/code&gt; alone, or &lt;code&gt;PYTHONIOENCODING&lt;/code&gt; alone, only fixes half of the problem. That tripped me up at first. &lt;strong&gt;Set both&lt;/strong&gt; and you're good.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;kaggle kernels status&lt;/code&gt; gives you the status; &lt;code&gt;kaggle kernels output&lt;/code&gt; gives you the output files and &lt;code&gt;&amp;lt;slug&amp;gt;.log&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Reading the log in Python and condensing it into a ~7-line summary plus one CSV row makes checking much easier&lt;/li&gt;
&lt;li&gt;Loading the token from a file and passing it to the child process means &lt;code&gt;.bat&lt;/code&gt; files and agents use the same path&lt;/li&gt;
&lt;li&gt;On Windows, use both &lt;code&gt;chcp 65001&lt;/code&gt; and &lt;code&gt;PYTHONIOENCODING=utf-8&lt;/code&gt; to avoid garbled text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compared to the days of scrolling through logs in Notepad, I now spend far less time checking runs, and I hand far less text to my agents. I hope this helps anyone else running Kaggle notebooks from their local machine!&lt;/p&gt;

</description>
      <category>kaggle</category>
      <category>python</category>
      <category>cli</category>
      <category>windows</category>
    </item>
  </channel>
</rss>
